Re: How I can read-back a serial value just inserted? - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: How I can read-back a serial value just inserted?
Date
Msg-id 20070118054909.GA21720@wolff.to
Whole thread Raw
In response to How I can read-back a serial value just inserted?  ("dfx" <dfx@dfx.it>)
List pgsql-general
On Mon, Jan 01, 2007 at 18:46:26 +0100,
  dfx <dfx@dfx.it> wrote:
> Dear Sirs,
>
> my question is very simple:
> when I insert a row whith a serial field, a value is automatically
> generated; how  can I know this value, strictly of my row, without the risk
> of to read the value of another subsequent insertion?

Use currval before calling nextval again (including implicitly) in the same
session. (What other sessions are doing won't change the value you see.)

In 8.2 you can use the RETURNING clause to get the value inserted.

pgsql-general by date:

Previous
From: "Alexi Gen"
Date:
Subject: Newbie questions (pg_global, tablespace, pg_temp, ...)
Next
From: Madison Kelly
Date:
Subject: Re: How I can read-back a serial value just inserted?