Re: Rules: A Modest Proposal

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: Greg Sabino Mullane <greg(at)turnstep(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Rules: A Modest Proposal
Date: 2009-10-05 14:09:17
Message-ID: 20091005140916.GB1518@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)org> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2009-10-05 14:14:36 Re: Privileges and inheritance
Previous Message Andrew Gierth 2009-10-05 13:53:56 Re: Rules: A Modest Proposal