Re: How I can read-back a serial value just inserted?

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: dfx <dfx(at)dfx(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How I can read-back a serial value just inserted?
Date: 2007-01-18 05:49:09
Message-ID: 20070118054909.GA21720@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Jan 01, 2007 at 18:46:26 +0100,
dfx <dfx(at)dfx(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Madison Kelly 2007-01-18 05:53:40 Re: How I can read-back a serial value just inserted?
Previous Message Alexi Gen 2007-01-18 05:32:18 Newbie questions (pg_global, tablespace, pg_temp, ...)