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

From Nick
Subject Reliability of CURRVAL in a RULE
Date
Msg-id 93c5ec95-e6da-4f0a-8b43-2a55d331e5d3@b38g2000prf.googlegroups.com
Whole thread Raw
Responses Re: Reliability of CURRVAL in a RULE  (Richard Huxton <dev@archonet.com>)
List pgsql-hackers
Is the use of CURRVAL in this example reliable in heavy use?

CREATE TABLE users ( id SERIAL NOT NULL, email VARCHAR(24) DEFAULT NULL, PRIMARY KEY (id)
);
CREATE TABLE users_with_email ( id INTEGER NOT NULL
);
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'));

I tried...

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

which was incrementing the sequence twice. Should I be using a trigger
instead? This rule seems quite simple and easy enough... if reliable. -
Nick


pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Automatic Client Failover
Next
From: Richard Huxton
Date:
Subject: Re: Reliability of CURRVAL in a RULE