X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 8A5D7D1BB49 for ; Fri, 9 Apr 2004 18:00:55 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 43542-08 for ; Fri, 9 Apr 2004 18:00:55 -0300 (ADT) Received: from jimsun.LinxNet.com (jimsun.linxnet.com [64.32.196.134]) by svr1.postgresql.org (Postfix) with ESMTP id B281DD1DB96 for ; Fri, 9 Apr 2004 18:00:52 -0300 (ADT) Received: by jimsun.LinxNet.com (Postfix, from userid 332) id 80FF24307; Fri, 9 Apr 2004 17:00:54 -0400 (EDT) To: pgsql-admin@postgresql.org Subject: Re: sequence value of the record just inserted. X-Sun-Charset: US-ASCII Reply-To: pgsql-admin@postgresql.org In-Reply-To: Message-Id: <20040409210054.80FF24307@jimsun.LinxNet.com> Date: Fri, 9 Apr 2004 17:00:54 -0400 (EDT) From: jseymour@LinxNet.com (Jim Seymour) X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/187 X-Sequence-Number: 13160 Ben Kim 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