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. I looked at the set transaction, but it doesn't seem to provide a way to set transaction write committed. Thanks,
> 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
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера