Re: [GENERAL] getting the value from nextval('sequencename')

From: Charles Tassell <ctassell(at)isn(dot)net>
To: pgsql-general(at)hub(dot)org
Subject: Re: [GENERAL] getting the value from nextval('sequencename')
Date: 1999-09-21 04:47:34
Message-ID: 4.1.19990921014414.00c0c8f0@mailer.isn.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If you are using transactions (as you probably should be) you can use
curval to get the last assigned value I believe. Something like:

insert into table (field) values ('val');
select curval(seq_name);

I just wrote something similar in PHP that reads back the OID of the insert
and then does a select fieldname from table where oid = last_oid; which
also works well. I believe there are ways to access the oid of your insert
from all of the languages with Postgres support.

At 05:40 PM 9/20/99, David Giffin wrote:
>
>Is there a way to tell what nextval('sequencename') returned? I have been
>doing a seperate query to get it. But in production this would lead to
>race conditions.
>
>Thanks,
>
>David
>
>
>************
>

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vadim Mikheev 1999-09-21 05:07:15 Re: [GENERAL] getting the value from nextval('sequencename')
Previous Message Charles Tassell 1999-09-21 04:43:07 Re: [GENERAL] Case sensitivity