Re: how to return the last inserted identity column value

Поиск
Список
Период
Сортировка
Искать
От
Ondrej Ivanič
Тема
Re: how to return the last inserted identity column value
Дата
Msg-id
CAM6mie+8_g1KAunU1oDfgWCDy-RrO3E8a4Ceo1+OvK6vUGGH+A@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 Scott Marlowe <scott.marlowe@gmail.com>
Re: how to return the last inserted identity column value Ondrej Ivanič <ondrej.ivanic@gmail.com>
Hi,

On 9 March 2012 05:20, Scott Marlowe  wrote:
> On Thu, Mar 8, 2012 at 11:16 AM,   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;

You can use lastval() or currval() functions:
http://www.postgresql.org/docs/9.1/static/functions-sequence.html


-- 
Ondrej Ivanic
(ondrej.ivanic@gmail.com)
В списке pgsql-general по дате отправления
От: Guillaume Lelarge
Дата:
FAQ