Re: INSERT and get ID

Поиск
Список
Период
Сортировка
Искать
От
Oliver Jowett
Тема
Re: INSERT and get ID
Дата
Msg-id
42E788D0.5050902@opencloud.com
Ответ на
INSERT and get ID (Peter.Zoche@materna.de)
Список
Дерево обсуждения
Re: INSERT and get ID Peter.Zoche@materna.de
Re: INSERT and get ID Csaba Nagy <nagy@ecircle-ag.com>
Re: INSERT and get ID Roland Walter <rwa@mosaic-ag.com>
Re: INSERT and get ID Sebastiaan van Erk <sebster@sebster.com>
Re: INSERT and get ID Dave Cramer <pg@fastcrypt.com>
Peter.Zoche@materna.de wrote:

> String insert = "INSERT INTO foo (id, val)
> VALUES( nextval('myseq'), 5 )";
> int count = statement.executeUpdate( insert );
> 
> I only get the row count of inserted rows. Do I have to query the
> database again to get the id? 

Currently, yes. You can usually do some trickery with currval() to run
both an INSERT and a SELECT in the same statement and avoid an extra
round-trip.

> Or is there another way? I have tried
> statement.executeUpdate( insert, Statement.RETURN_GENERATED_KEYS);
> but I get an PSQLException saying that the feature of auto-generated keys 
> is not supported.

Right, this really needs server-side support before we can implement it
(INSERT ... RETURNING ... or similar)

-O
В списке pgsql-jdbc по дате отправления
От: Peter.Zoche@materna.de
Дата:
Сообщение: INSERT and get ID
От: Dave Cramer
Дата:
Сообщение: Re: INSERT and get ID
FAQ