Re: getting back autonumber just inserted - Mailing list pgsql-sql

From Scott Marlowe
Subject Re: getting back autonumber just inserted
Date
Msg-id 1120767709.8208.188.camel@state.g2switchworks.com
Whole thread Raw
In response to Re: getting back autonumber just inserted  (Theodore Petrosky <tedpet5@yahoo.com>)
Responses Re: getting back autonumber just inserted
List pgsql-sql
On Thu, 2005-07-07 at 15:14, Theodore Petrosky wrote:
> you have to use currval inside a transaction...
> 
> begin;
> insert something that increments the counter;
> select currval('sequence_name');
> end;
> 
> using currval inside a transaction guarantees that the
> value is correct for your insert statement and has not
> changed by another insert statement.

Actually, whether you use it inside a transaction or not, as long as
it's in the same session / connection, it is guaranteed to "do the right
thing."

Test it, you'll see.


pgsql-sql by date:

Previous
From: Theodore Petrosky
Date:
Subject: Re: getting back autonumber just inserted
Next
From: mail TechEvolution
Date:
Subject: Re: getting back autonumber just inserted