Re: GetLastInsertID ?

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Stephane Pinel <spinel(at)noos(dot)fr>
Cc: PostgreSQL general list <pgsql-general(at)postgresql(dot)org>
Subject: Re: GetLastInsertID ?
Date: 2004-01-01 16:20:23
Message-ID: 1072974023.25136.2.camel@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)Elphick(at)lfix(dot)co(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tino Wildenhain 2004-01-01 16:33:25 Re: Is my MySQL Gaining ?
Previous Message Dave Cramer 2004-01-01 16:19:57 Re: GetLastInsertID ?