Re: LAST_INSERT_ID equivalent

From: Erik Price <eprice(at)ptc(dot)com>
To: Edmund Dengler <edmundd(at)eSentire(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: LAST_INSERT_ID equivalent
Date: 2003-06-12 17:44:16
Message-ID: 3EE8BBF0.7050306@ptc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

Thanks,

Erik

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sean Chittenden 2003-06-12 17:45:57 Re: Running two versions on same server
Previous Message Richard Huxton 2003-06-12 17:42:28 Re: LAST_INSERT_ID equivalent