Ben Kim <[EMAIL PROTECTED]> wrote: > > > Dear admins, > > I have a table whose primary key is a record_id with serial type. > > I would like to know, when I insert a new row, what was the value of the > record_id that I just inserted. Since this is a multi user application, I > cannot simply select max of the record_id or currval of the sequence.
You certainly can use currval(); In session #1 I do... jseymour=> create table foo3 (bar serial, baz int); jseymour=> insert into foo3 (baz) values (1); This will put "1" in for column "bar". In session #2 I do... jseymour=> insert into foo3 (baz) values (1); This will put "2" in for column "bar". Now back to session #1... jseymour=> select currval('foo3_bar_seq'); currval --------- 1 (1 row) And session #2... jseymour=> select currval('foo3_bar_seq'); currval --------- 2 (1 row) HTH, Jim ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org