Re: LAST_INSERT_ID equivalent

Поиск
Список
Период
Сортировка
От Erik Price
Тема Re: LAST_INSERT_ID equivalent
Дата
Msg-id 3EE8D1C2.3080808@ptc.com
обсуждение исходный текст
Ответ на Re: LAST_INSERT_ID equivalent  (Ericson Smith <eric@did-it.com>)
Ответы Re: LAST_INSERT_ID equivalent  (Bruno Wolff III <bruno@wolff.to>)
Re: LAST_INSERT_ID equivalent  (Ericson Smith <eric@did-it.com>)
Список pgsql-general

Ericson Smith wrote:
> While many others use currval(), we tend to grab the next ID provided by
> nextval('seq') and use that to be inserted with the record. The process
> is very atomic, and the ID is available to be used by the rest of your
> program. The only drawback is if your insert query fails there will be a
> hole in the sequence.

So you're saying that you perform a pre-query to fetch the nextval, then
you include that in your query where you perform the INSERT?  I see.
Since this is all part of the same transaction, the nextval value won't
overwrite another simultaneous INSERT, I assume.  This seems like a good
way to do it too.  I don't mind the holes in the sequence, but wouldn't
this INSERT cause the sequence to increment the primary key yet again?



Erik


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

Предыдущее
От: Clay Luther
Дата:
Сообщение: Choosing Between PL/PGSQL or C/C++ for Triggers/Store Procs
Следующее
От: Steve Crawford
Дата:
Сообщение: Re: need a method to ping a running database