Re: Getting OID after Insert

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: Getting OID after Insert
Дата
Msg-id 20011019020807.K7364@svana.org
обсуждение исходный текст
Ответ на Getting OID after Insert  (Bruce Cota <bruce@vivi.com>)
Список 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 по дате отправления:

Предыдущее
От: Gordan Bobic
Дата:
Сообщение: Re: FTI Queries and Explain (long)
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: Break both? (Was To Postgres Devs : Wouldn't changing