pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Forest Wilkinson <fspam@home.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: are NEW and OLD rule attributes broken?
Date: Fri, 18 May 2001 15:20:47 -0400
Message-ID: <22865.990213647@sss.pgh.pa.us> (raw)
In-Reply-To: <01051811361700.01348@bartok>
References: <01051811361700.01348@bartok>

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



view thread (2+ messages)

Message-ID: <22865.990213647@sss.pgh.pa.us>
Permalink:  ../22865.990213647@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/22865.990213647@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, fspam@home.com
  Subject: Re: are NEW and OLD rule attributes broken?
  In-Reply-To: <22865.990213647@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox