Re: NEW in Rule makes another nextval call?

From: Richard Huxton <dev(at)archonet(dot)com>
To: Sven Willenberger <sven(at)dmv(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: NEW in Rule makes another nextval call?
Date: 2005-10-20 14:01:29
Message-ID: 4357A339.5060202@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Sven Willenberger wrote:
> Is this intended behavior? or is the NEW
> acting as a macro that is replace by "nextval(<sequence name>)" ?

Well, it's understood behaviour even if not quite "intended".

You are quite right, rules basically act like macros with all the
limitations they have. What is actually happening behind the scenes is
that the query is being rewritten to alter the query-plan tree. You
should be able to get your rule to work by referring to
currval(<sequence-name>) rather than NEW.custid.

However, in this particular case I think you want an after insert
trigger on customer rather than a rule.

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-10-20 14:04:26 Re: doc typo sql-reindex.html psql vs. postgres
Previous Message Andrew Kelly 2005-10-20 13:48:43 Re: [HACKERS] 'a' == 'a '