Re: GetLastInsertID ?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Stephane Pinel <spinel(at)noos(dot)fr>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: GetLastInsertID ?
Date: 2004-01-01 16:14:43
Message-ID: 20040101161443.GA4788@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If you use nextval before the insert, you should use the value in the insert
itself. Afterwards you can use currval to get the just inserted value.

I'm surprised you can't find this in the archives, it's asked on an almost
weekly basis.

It's also question 4.15.2 of the FAQ:

http://www.postgresql.org/docs/faqs/FAQ.html#4.15.2

Hope this helps,

On Thu, Jan 01, 2004 at 04:10:56PM +0100, Stephane Pinel wrote:
> Happy new year to all pgsql fans !
>
> Sorry for this trivial question but I couldn't find an answer in the
> archives :
>
> I use SERIAL type in tables for id columns in order to auto increment
> them. Is there a way to get
> the last inserted id in the table like we do with MySQL using the
> GetLastInsertID ?
>
> My need is to get back the new id just after inserting. Is nextval can
> respond to this need if I call it
> just before inserting ?
>
> Thank you very much.
>
> Stéphane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> (... have gone from d-i being barely usable even by its developers
> anywhere, to being about 20% done. Sweet. And the last 80% usually takes
> 20% of the time, too, right?) -- Anthony Towns, debian-devel-announce

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dave Cramer 2004-01-01 16:19:57 Re: GetLastInsertID ?
Previous Message Dennis Bjorklund 2004-01-01 16:12:25 Re: GetLastInsertID ?