Re: new.id has wrong value in INSERT RULE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Ian McFarland" <ian(at)lightershade(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: new.id has wrong value in INSERT RULE
Date: 2005-09-16 14:23:11
Message-ID: 361.1126880591@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Ian McFarland" <ian(at)lightershade(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-09-16 14:25:12 Re: Strange Bug in exim4 postgresql lookup code or libpq?
Previous Message Bill Moseley 2005-09-16 14:18:25 Question about a query plan