Problems with transactions and sequences - Mailing list pgsql-general

From Sune Nielsen
Subject Problems with transactions and sequences
Date
Msg-id j0trkvkn9i9n33ju2g909r3chs1rm2t5s9@4ax.com
Whole thread Raw
Responses Re: Problems with transactions and sequences  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Problems with transactions and sequences  ("Shridhar Daithankar" <shridhar_daithankar@persistent.co.in>)
List 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@image.dk
Student at
Dept. of Computer Science
Copenhagen University
http://www.diku.dk

pgsql-general by date:

Previous
From: "Marc G. Fournier"
Date:
Subject: Re: The ..... worm
Next
From: Thierry Missimilly
Date:
Subject: [Fwd: Postgresql-7.4beta1 compilation error]