Re: LAST_INSERT_ID equivalent

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Erik Price <eprice(at)ptc(dot)com>
Cc: Edmund Dengler <edmundd(at)eSentire(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: LAST_INSERT_ID equivalent
Date: 2003-06-12 18:23:15
Message-ID: 20030612182315.GA4978@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jun 12, 2003 at 13:44:16 -0400,
Erik Price <eprice(at)ptc(dot)com> wrote:
>
>
> Edmund Dengler wrote:
> >Greetings all!
> >
> >I believe
> > select currval('sequence_name');
> >should satisfy your needs. Within a transaction it will stay the same.
>
> Ed, thanks, this looks like what I was looking for --
>
> however, I am concerned by your disclaimer. Can you explain that a
> little bit? I read it to mean "if you try to use this technique within
> a transaction where you are INSERTing a new record, it will not reflect
> the new record's ID". So then in order to determine the new record's ID
> I would need to use
>
> SELECT CURRVAL('sequence_name') + 1;
>
> within the transaction.

No. You just want to use currval. The comment was referring to other
transactions calling nextval while the transaction of interest is
proceeding.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ericson Smith 2003-06-12 18:28:25 Re: LAST_INSERT_ID equivalent
Previous Message Stephan Szabo 2003-06-12 18:05:05 Re: Cast: timestamp to integer