Skip site navigation (1) Skip section navigation (2)

Re: returning id

From: Lonni J Friedman <netllama(at)gmail(dot)com>
To: Marc Fromm <Marc(dot)Fromm(at)wwu(dot)edu>
Cc: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: returning id
Date: 2011-09-20 19:44:52
Message-ID: CAP=oouEkQAF1yrbBBFe=c9XAeM3awMpOndi=+8C_p-Jo0Roi=w@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-admin
On Tue, Sep 20, 2011 at 12:31 PM, Marc Fromm <Marc(dot)Fromm(at)wwu(dot)edu> wrote:
> Can I use “RETURNING id” in an insert statement with postgresql version
> 8.1.10?
>
> I cannot find a clear example on how to use it to capture the id created by
> the insert statement into a variable in PHP.
>
>
>
> Many examples are like this but don’t state how to access the returned id:
>
> INSERT INTO Addresses (address, city, state, postalcode) VALUES ('123 Main
> St.','Springfield','MA','01109') RETURNING id;
>

Is there a reason why you can't use the currval function:
select currval('id_seq')

In response to

pgsql-admin by date

Next:From: Tom LaneDate: 2011-09-20 19:55:37
Subject: Re: returning id
Previous:From: Marc FrommDate: 2011-09-20 19:31:10
Subject: returning id

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group