pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
returning id
4+ messages / 4 participants
[nested] [flat]

* returning id
@ 2011-09-20 19:31 Marc Fromm <Marc.Fromm@wwu.edu>
  2011-09-20 19:44 ` Re: returning id Lonni J Friedman <netllama@gmail.com>
  2011-09-20 19:55 ` Re: returning id Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 4+ messages in thread

From: Marc Fromm @ 2011-09-20 19:31 UTC (permalink / raw)
  To: pgsql-admin

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;

Thanks

Marc

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: returning id
  2011-09-20 19:31 returning id Marc Fromm <Marc.Fromm@wwu.edu>
@ 2011-09-20 19:44 ` Lonni J Friedman <netllama@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Lonni J Friedman @ 2011-09-20 19:44 UTC (permalink / raw)
  To: Marc Fromm <Marc.Fromm@wwu.edu>; +Cc: pgsql-admin

On Tue, Sep 20, 2011 at 12:31 PM, Marc Fromm <Marc.Fromm@wwu.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')



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: returning id
  2011-09-20 19:31 returning id Marc Fromm <Marc.Fromm@wwu.edu>
@ 2011-09-20 19:55 ` Tom Lane <tgl@sss.pgh.pa.us>
  2011-09-20 20:09   ` Re: returning id Guillaume Lelarge <guillaume@lelarge.info>
  1 sibling, 1 reply; 4+ messages in thread

From: Tom Lane @ 2011-09-20 19:55 UTC (permalink / raw)
  To: Marc Fromm <Marc.Fromm@wwu.edu>; +Cc: pgsql-admin

Marc Fromm <Marc.Fromm@wwu.edu> writes:
> Can I use "RETURNING id" in an insert statement with postgresql version 8.1.10?

No.  I don't recall just when RETURNING was added, but for sure it was
after 8.1.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: returning id
  2011-09-20 19:31 returning id Marc Fromm <Marc.Fromm@wwu.edu>
  2011-09-20 19:55 ` Re: returning id Tom Lane <tgl@sss.pgh.pa.us>
@ 2011-09-20 20:09   ` Guillaume Lelarge <guillaume@lelarge.info>
  0 siblings, 0 replies; 4+ messages in thread

From: Guillaume Lelarge @ 2011-09-20 20:09 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Marc Fromm <Marc.Fromm@wwu.edu>; pgsql-admin

On Tue, 2011-09-20 at 15:55 -0400, Tom Lane wrote:
> Marc Fromm <Marc.Fromm@wwu.edu> writes:
> > Can I use "RETURNING id" in an insert statement with postgresql version 8.1.10?
> 
> No.  I don't recall just when RETURNING was added, but for sure it was
> after 8.1.
> 

I checked. It appeared in 8.2. Sooner than I expected actually.


-- 
Guillaume
  http://blog.guillaume.lelarge.info
  http://www.dalibo.com




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2011-09-20 20:09 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-09-20 19:31 returning id Marc Fromm <Marc.Fromm@wwu.edu>
2011-09-20 19:44 ` Lonni J Friedman <netllama@gmail.com>
2011-09-20 19:55 ` Tom Lane <tgl@sss.pgh.pa.us>
2011-09-20 20:09   ` Guillaume Lelarge <guillaume@lelarge.info>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox