Getting last inserted SERIAL

Поиск
Список
Период
Сортировка
От mgarriss
Тема Getting last inserted SERIAL
Дата
Msg-id 3F52BFBF.1040301@earthlink.net
обсуждение исходный текст
Ответы Re: Getting last inserted SERIAL  (Dennis Björklund <db@zigo.dhs.org>)
Re: Getting last inserted SERIAL  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-general
Given this table:

CREATE TABLE test ( id SERIAL, example TEXT );

An implicit sequence is created as show in this message:

NOTICE:  CREATE TABLE will create implicit sequence 'test_id_seq' for
SERIAL column 'test.id'

How do I retrieve the last 'id' that was inserted?  I have a process
that does an insert and then needs the value of the id column of the row
it just inserted so that that row can be used later in processing.
First thought is "SELECT CURRVAL('test_id_seq');" but this assumes that
there is only one connection inserting into this table, bad assumption.
Next idea is the make 'id' an INT4 and set it explicitly with a value
that I select from an explicitly created sequence.  This method seems a
bit inelegant.  Any ideas?

TIA
Michael Garriss


В списке pgsql-general по дате отправления:

Предыдущее
От: Doug McNaught
Дата:
Сообщение: Re: Prevent from Deletion
Следующее
От: Weiping He
Дата:
Сообщение: Re: how to group by a joined query?