Reliability of CURRVAL in a RULE

From: Nick <nboutelier(at)hotmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Reliability of CURRVAL in a RULE
Date: 2008-08-05 03:39:33
Message-ID: 93c5ec95-e6da-4f0a-8b43-2a55d331e5d3@b38g2000prf.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-08-05 05:41:14 Re: DROP DATABASE always seeing database in use
Previous Message Tom Lane 2008-08-05 02:56:52 Re: Automatic Client Failover