Re: Getting OID after Insert - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Getting OID after Insert
Date
Msg-id 20011019020807.K7364@svana.org
Whole thread Raw
In response to Getting OID after Insert  (Bruce Cota <bruce@vivi.com>)
List pgsql-general
On Thu, Oct 18, 2001 at 10:29:09AM -0400, Bruce Cota wrote:
> Thank you!
>
> Hopefully that getlastoid refers to the last oid
> created in this session or transaction?  I can't find it
> mentioned in the docs anywhwere.

last insert, iirc.

> Nextval and curval aren't specific to the transaction or
> session, right?  so that would be problematic  in a
> multi-user environment.

Sure they are. Currval returns the last value returned in this transaction.
This is a production database system and not having it multiuser safe would
be stupid no?

So you can do stuff like:

insert into invoice (customer,date,etc...);
insert into item (invoice_id, ...) values ( currval('invoice_id_seq'), ... );

etc...

multiuser safe. very cool. Remember, oid are not really guarenteed to be
unique...

--
Martijn van Oosterhout <kleptog@svana.org>
http://svana.org/kleptog/
> Magnetism, electricity and motion are like a three-for-two special offer:
> if you have two of them, the third one comes free.

pgsql-general by date:

Previous
From: Gordan Bobic
Date:
Subject: Re: FTI Queries and Explain (long)
Next
From: Bruce Momjian
Date:
Subject: Re: Break both? (Was To Postgres Devs : Wouldn't changing