Re: Getting OID after Insert

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Bruce Cota <bruce(at)vivi(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Getting OID after Insert
Date: 2001-10-18 16:08:07
Message-ID: 20011019020807.K7364@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2001-10-18 16:27:33 Re: Break both? (Was To Postgres Devs : Wouldn't changing
Previous Message Gordan Bobic 2001-10-18 16:02:52 Re: FTI Queries and Explain (long)