Re: Reliability of CURRVAL in a RULE - Mailing list pgsql-hackers

From Richard Huxton
Subject Re: Reliability of CURRVAL in a RULE
Date
Msg-id 48980194.3060005@archonet.com
Whole thread Raw
In response to Reliability of CURRVAL in a RULE  (Nick <nboutelier@hotmail.com>)
List pgsql-hackers
Nick wrote:
> Is the use of CURRVAL in this example reliable in heavy use?

Nick - the hackers list is for people interested in working on the 
code-base of PostgreSQL itself. This would have been better on the 
general or sql lists.

> CREATE RULE add_email AS ON INSERT TO users WHERE (NEW.email IS NULL)
> DO INSERT INTO users_with_email (id) VALUES (CURRVAL('users_id_seq'));

Short answer no. Rules are like macros and you can end up with 
unexpected multiple evaluations and strange order of execution. See the 
mailing list archives for details and try inserting multiple users in 
one go to see an example of a problem.

--   Richard Huxton  Archonet Ltd


pgsql-hackers by date:

Previous
From: Nick
Date:
Subject: Reliability of CURRVAL in a RULE
Next
From: "Greg Stark"
Date:
Subject: Re: Automatic Client Failover