Re: set transaction question

Поиск
Список
Период
Сортировка
От Gregory Wood
Тема Re: set transaction question
Дата
Msg-id 006401c0dfa6$168d7b70$7889ffcc@comstock.com
обсуждение исходный текст
Ответ на set transaction question  (HYip <hualinyip@earthlink.net>)
Список pgsql-general
> Inside a transaction,
>
> I insert a row into the table, with an autonumber id.
> Now I want to return the id of the newly inserted row.  How can I do
> that?
>
> It seems that the first insert statement is not committed, and so the
> second statement couldn't return the newly id.

SELECT currval('table_field_seq'); should work fine from inside a
transaction. The reason is that it retrieves the last value of the sequence
that was used by that backend, *not* the last value inserted into the table.
Therefore, it doesn't matter whether that value was committed or not.

Greg


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

Предыдущее
От: Vincent Roberts
Дата:
Сообщение: Function to detect trigger recursion
Следующее
От: manuel@des01.sanyres.es
Дата:
Сообщение: Re: Which Front End for Postgresql