From: jseymour@LinxNet.com
To: pgsql-admin@postgresql.org
Subject: Re: sequence value of the record just inserted.
Date: Fri, 9 Apr 2004 17:00:54 -0400 (EDT)
Message-ID: <20040409210054.80FF24307@jimsun.LinxNet.com> (raw)
In-Reply-To: <Pine.GSO.4.10.10404090954300.10715-100000@edsun.coe.tamu.edu>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: jseymour@LinxNet.com
Subject: Re: sequence value of the record just inserted.
In-Reply-To: <20040409210054.80FF24307@jimsun.LinxNet.com>
References: <Pine.GSO.4.10.10404090954300.10715-100000@edsun.coe.tamu.edu> <20040409210054.80FF24307@jimsun.LinxNet.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox