Re: are NEW and OLD rule attributes broken? - Mailing list pgsql-sql

From Tom Lane
Subject Re: are NEW and OLD rule attributes broken?
Date
Msg-id 22865.990213647@sss.pgh.pa.us
Whole thread Raw
In response to are NEW and OLD rule attributes broken?  (Forest Wilkinson <fspam@home.com>)
List pgsql-sql
Forest Wilkinson <fspam@home.com> writes:
> What's going on here?  My rule inserted a new row into bar, but the fooid 
> it used was not the new value inserted into foo.  It looks like my rule is 
> inserting "nextval('foo_fooid_seq')" into the bar table, rather than 
> inserting the new primary key from the foo table.  Is this the intended 
> behavior?

NEW and OLD are effectively macros, not variables.  So yes, you get
extra evaluations of nextval() this way.  I think there are cases where
that is actually what you want (not in this case obviously :-().  It
would be fairly difficult to change, anyway.

> How can I get the result I want?

If you want to copy the data actually inserted, a trigger is a much
better bet than a rule.
        regards, tom lane


pgsql-sql by date:

Previous
From: Forest Wilkinson
Date:
Subject: are NEW and OLD rule attributes broken?
Next
From: Martín Marqués
Date:
Subject: Re: search for groups with a user