Re: Fetching generated keys

Поиск
Список
Период
Сортировка
От Heikki Linnakangas
Тема Re: Fetching generated keys
Дата
Msg-id 45EC86E2.8020506@enterprisedb.com
обсуждение исходный текст
Ответ на Fetching generated keys  ("Mike Clements" <mclement@progress.com>)
Ответы Re: Fetching generated keys  ("Mike Clements" <mclement@progress.com>)
Re: Fetching generated keys  (Dave Cramer <pg@fastcrypt.com>)
Re: Fetching generated keys  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-jdbc
Mike Clements wrote:
> Up to now, we were selecting the current value of the sequence
> immediately after the insert. I thought this was safe because
> transactions should be isolated. But now I realize this could
> potentially fail because the default transaction isolation is "read
> committed". Thus if another connection inserts into the same table,
> causing the sequence to increment, if it commits before we read the
> sequence value, we might read the wrong value (the value as incremented
> by the other transaction, not the value as it was for our own insert).

You should use the lastval-function. It retrieves the last value
returned in your connection. "SELECT lastval('sequence')"

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

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

Предыдущее
От: "Mike Clements"
Дата:
Сообщение: Fetching generated keys
Следующее
От: "Mike Clements"
Дата:
Сообщение: Re: Fetching generated keys