Re: GetLastInsertID ? - Mailing list pgsql-general

From Oliver Elphick
Subject Re: GetLastInsertID ?
Date
Msg-id 1072974023.25136.2.camel@linda.lfix.co.uk
Whole thread Raw
In response to GetLastInsertID ?  (Stephane Pinel <spinel@noos.fr>)
List pgsql-general
On Thu, 2004-01-01 at 15: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 ?

You can use currval() after the insert (specifying DEFAULT for the
SERIAL field), or nextval() to get an id to use in the insert.

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "The LORD shall preserve thy going out and thy coming
      in from this time forth, and even for evermore."
                                    Psalms 121:8


pgsql-general by date:

Previous
From: Dave Cramer
Date:
Subject: Re: GetLastInsertID ?
Next
From: Tino Wildenhain
Date:
Subject: Re: Is my MySQL Gaining ?