Received: from sss.pgh.pa.us (sss.pgh.pa.us [216.151.103.158]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f4IJKqA45271 for ; Fri, 18 May 2001 15:20:52 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.3/8.11.3) with ESMTP id f4IJKlR22868; Fri, 18 May 2001 15:20:47 -0400 (EDT) To: Forest Wilkinson cc: pgsql-sql@postgresql.org Subject: Re: are NEW and OLD rule attributes broken? In-reply-to: <01051811361700.01348@bartok> References: <01051811361700.01348@bartok> Comments: In-reply-to Forest Wilkinson message dated "Fri, 18 May 2001 11:36:17 -0700" Date: Fri, 18 May 2001 15:20:47 -0400 Message-ID: <22865.990213647@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200105/204 X-Sequence-Number: 3021 Forest Wilkinson 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