Re: Retrieving last InsertedID : INSERT... RETURNING safe ?

Поиск
Список
Период
Сортировка
От Guillaume Cottenceau
Тема Re: Retrieving last InsertedID : INSERT... RETURNING safe ?
Дата
Msg-id 87prurrh87.fsf@mnc.ch
обсуждение исходный текст
Ответ на Re: Retrieving last InsertedID : INSERT... RETURNING safe ?  ("Heikki Linnakangas" <heikki@enterprisedb.com>)
Ответы Re: Retrieving last InsertedID : INSERT... RETURNING safe ?  (Dave Cramer <davec@fastcrypt.com>)
Re: Retrieving last InsertedID : INSERT... RETURNING safe ?  (Dave Cramer <pg@fastcrypt.com>)
Список pgsql-jdbc
"Heikki Linnakangas" <heikki 'at' enterprisedb.com> writes:

> spastor@motionsponsor.com wrote:
>> Only one exception is regarding the best method to retrieve the last
>> inserted id (serial). There are many posts on this topic but i
>> couldn t find a definitive response. I am using postgresql version
>> 8.2.6 and jdbc  8.2_p505, i ve been experiencing INSERT statement
>> with RETURNING myID, using an executeQuery it works great, i
>> retrieve the proper value everytime at least  from the few tests i
>> have been doin  locally.
>> Is it THAT easy or could this method break somehow in a live environement ?
>
> It is that easy, and that is a good way to do it.
>
> Alternatively, if you need to support older PostgreSQL version for
> example, you could use a "SELECT currval('sequence')" query after the
> INSERT.

Well, that other solution is dangerous in case multiple inserts
to that table are done concurrently; a quite common usage pattern
with java web applications handling multiple HTTP requests with
concurrent java threads..

--
Guillaume Cottenceau

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

Предыдущее
От:
Дата:
Сообщение: Re: Retrieving last InsertedID : INSERT... RETURNING safe ?
Следующее
От: Dave Cramer
Дата:
Сообщение: Re: Retrieving last InsertedID : INSERT... RETURNING safe ?