Re: lastrowid and INSERT ... RETURNING

Cliff Wells <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <1212800331.32540.90.camel@portable-evil>
On Wed, 2006-07-26 at 08:45 +0200, Federico Di Gregorio wrote:
> Il giorno mar, 25/07/2006 alle 15.22 -0700, craigp ha scritto:
> > there's a todo item at
> > http://www.postgresql.org/docs/faqs.TODO.html (search
> > for returning) which would return columns/expressions on
> > insert/update. so
> > if/when that's done there'll be a mechanism to support the use-case of
> > returning the primary-key of a newly-inserted row (among others). 
> 
> That would be neat. Please, poke at me when it is ready in pg. :)

Poke.  Added in 8.2.4.

test=# create table foo ( id serial primary key not null, name text );

test=# insert into foo ( name ) values ( 'cliff' ) returning id;
 id 
----
  1
(1 row)

test=# insert into foo ( name ) values ( 'cliff 2' ) returning *;
 id |  name   
----+---------
  2 | cliff 2
(1 row)



Regards,
Cliff
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.