Re: how to return the last inserted identity column value

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: how to return the last inserted identity column value
Дата
Msg-id CAOR=d=1qALu8uBkcxi239WADErnxeuvge3w-mgKMWp6t-eaTMw@mail.gmail.com
обсуждение исходный текст
Ответ на how to return the last inserted identity column value  (<mgould@isstrucksoftware.net>)
Ответы Re: how to return the last inserted identity column value  (Ondrej Ivanič <ondrej.ivanic@gmail.com>)
Список pgsql-general
On Thu, Mar 8, 2012 at 11:16 AM,  <mgould@isstrucksoftware.net> wrote:
> In some languges you can use set l_localid = @@identity which returns
> the value of the identity column defined in the table.  How can I do
> this in Postgres 9.1

Assuming you created a table like so:

smarlowe=# create table test (id serial,info text);
NOTICE:  CREATE TABLE will create implicit sequence "test_id_seq" for
serial column "test.id"
CREATE TABLE

Then use returning:

smarlowe=# insert into test (info) values ('this is a test') returning id;
 id
----
  1
(1 row)

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

Предыдущее
От:
Дата:
Сообщение: how to return the last inserted identity column value
Следующее
От: Achilleas Mantzios
Дата:
Сообщение: Re: How to erase transaction logs on PostgreSQL