Re: Rules: A Modest Proposal - Mailing list pgsql-hackers

From Martijn van Oosterhout
Subject Re: Rules: A Modest Proposal
Date
Msg-id 20091005140916.GB1518@svana.org
Whole thread Raw
In response to Re: Rules: A Modest Proposal  (Andrew Gierth <andrew@tao11.riddles.org.uk>)
Responses Re: Rules: A Modest Proposal
List pgsql-hackers
On Mon, Oct 05, 2009 at 02:53:56PM +0100, Andrew Gierth wrote:
> Here are a couple of the more common ones:
>
> 1) any reference in an insert rule to NEW.col where col has a volatile
>    default, or the expression in the insert statement was volatile, or
>    the expression's value is changed by the insert, will do the wrong
>    thing:

ISTM it may be possible to use the new WITH construct here. So the rule
evaluation for the following

> create table t (a integer);
> create table t_log (a integer);
> create rule t_ins AS ON insert TO t do also insert into t_log values (NEW.a);
> insert into t values (floor(random()*1000)::integer);

becomes something like:

WITH NEW AS ( insert into t values (floor(random()*1000)::integer); RETURNING *
)
insert into t_log values (NEW.a);

Would this not have the required semantics?

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

pgsql-hackers by date:

Previous
From: Andrew Gierth
Date:
Subject: Re: Rules: A Modest Proposal
Next
From: Tom Lane
Date:
Subject: Re: Privileges and inheritance