Re: new.id has wrong value in INSERT RULE - Mailing list pgsql-general

From Tom Lane
Subject Re: new.id has wrong value in INSERT RULE
Date
Msg-id 361.1126880591@sss.pgh.pa.us
Whole thread Raw
In response to new.id has wrong value in INSERT RULE  ("Ian McFarland" <ian@lightershade.com>)
List pgsql-general
"Ian McFarland" <ian@lightershade.com> writes:
> CREATE RULE table_b_insert_rule  AS ON INSERT TO table_b
>     DO (UPDATE table_b SET active = 'f', yield = new.id WHERE table_a_id
> = new.table_a_id AND id != new.id;);

Rules are macros.  Since what is substituted for new.id in this case is
a nextval() call, you have a multiple-evaluation problem.  The above is
a pretty horrid way to do things anyway --- you should probably be using
a trigger instead.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Strange Bug in exim4 postgresql lookup code or libpq?
Next
From: Doug Bloebaum
Date:
Subject: Re: Create a pg table from CSV with header rows