Re: GetLastInsertID ?

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Stephane Pinel <spinel(at)noos(dot)fr>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: GetLastInsertID ?
Date: 2004-01-01 16:19:57
Message-ID: 1072973997.1671.31.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You should use curval after inserting

and this can be done in one step

insert into foo (c1,c2,...) values ( v1, v2...); select curval( sequence
);

Dave
On Thu, 2004-01-01 at 10:10, 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
>
--
Dave Cramer
519 939 0336
ICQ # 1467551

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Oliver Elphick 2004-01-01 16:20:23 Re: GetLastInsertID ?
Previous Message Martijn van Oosterhout 2004-01-01 16:14:43 Re: GetLastInsertID ?