Re: sequence value of the record just inserted.
От | jseymour@LinxNet.com (Jim Seymour) |
---|---|
Тема | Re: sequence value of the record just inserted. |
Дата | |
Msg-id | 20040409210054.80FF24307@jimsun.LinxNet.com обсуждение исходный текст |
Ответ на | sequence value of the record just inserted. (Ben Kim <bkim@coe.tamu.edu>) |
Список | pgsql-admin |
Ben Kim <bkim@coe.tamu.edu> 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
В списке pgsql-admin по дате отправления: