Problems with transactions and sequences

From: Sune Nielsen <sunegn(at)image(dot)dk>
To: pgsql-general(at)postgresql(dot)org
Subject: Problems with transactions and sequences
Date: 2003-08-28 12:35:35
Message-ID: j0trkvkn9i9n33ju2g909r3chs1rm2t5s9@4ax.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello All!

Im suffering an appearantly common problem with psql, although I
haven't been able to locate the proper solution.
Using phpPgAdmin I've created a relation (note: this relation is
grossly simplified but the problem remains the same) :

CREATE TABLE Users
( bid SERIAL,
name CHAR(8) NOT NULL,
PRIMARY KEY (bid)
);

Now, the problem is that I wish to extract the sequence number from a
newly inserted user, like this:

INSERT INTO Users (name) VALUES ('JohnDoe');
SELECT CURRVAL('users_bid_seq');

This works perfectly(!), but my project involves multiple simultanous
users so I have to use transactions like this:

BEGIN;
INSERT INTO Users (name) VALUES ('JohnDoe');
SELECT CURRVAL('users_bid_seq');
COMMIT;

This, however, doesn't work although I thought it should. It doesn't
return anything at all?!?! Could somebody explain me what I'm doing
wrong, or tell my how to do it instead?

Any help would be greatly appreciated!

--
Sune Nielsen sunegn(at)image(dot)dk
Student at
Dept. of Computer Science
Copenhagen University
http://www.diku.dk

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bo Lorentsen 2003-08-28 12:52:57 Re: mysql's last_insert_id
Previous Message Nigel J. Andrews 2003-08-28 12:16:14 Re: plpgsql FOUND Variable