Search Postgresql Archives

Re: how to return the last inserted identity column value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 8, 2012 at 11:16 AM,  <mgould@xxxxxxxxxxxxxxxxxxxx> 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)

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux