Re: Reliability of CURRVAL in a RULE

From: Richard Huxton <dev(at)archonet(dot)com>
To: Nick <nboutelier(at)hotmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Reliability of CURRVAL in a RULE
Date: 2008-08-05 07:30:28
Message-ID: 48980194.3060005@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Stark 2008-08-05 08:03:51 Re: Automatic Client Failover
Previous Message Simon Riggs 2008-08-05 06:52:29 Re: Automatic Client Failover