Re: getting back autonumber just inserted - Mailing list pgsql-sql

From Alvaro Herrera
Subject Re: getting back autonumber just inserted
Date
Msg-id 20050707180329.GA11332@alvh.no-ip.org
Whole thread Raw
In response to getting back autonumber just inserted  (mail TechEvolution <mail@techevolution.be>)
Responses Re: getting back autonumber just inserted
List pgsql-sql
On Thu, Jul 07, 2005 at 07:50:16PM +0200, mail TechEvolution wrote:
> hello
> 
> i ame a newbie to PostGreSQL, I ame using PostGreSQL 8.0 
> (windowsinstaller) on a xp prof platform
> 
> i would like to get back the autonumber from the last record inserted, 
> for other SQL db (m$ sql db ...) i could use:
> SELECT @@ IDENTITY
> 
> can someone help me by informing me what the SQL syntax is to be used 
> with PostGreSQL db and get the same result, the last autonumber inserted?

You use the currval() function, using the name of the involved sequence
as parameter.  There is a pg_get_serial_sequence() function, to which
you give the table name and column name, and it will give you the
sequence name.

-- 
Alvaro Herrera (<alvherre[a]alvh.no-ip.org>)
Oh, oh, las chicas galacianas, lo harán por las perlas,
¡Y las de Arrakis por el agua! Pero si buscas damas
Que se consuman como llamas, ¡Prueba una hija de Caladan! (Gurney Halleck)


pgsql-sql by date:

Previous
From: mail TechEvolution
Date:
Subject: getting back autonumber just inserted
Next
From: mail TechEvolution
Date:
Subject: Re: getting back autonumber just inserted