Re: getting back autonumber just inserted

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: lorid <lorid(at)dri(dot)edu>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: getting back autonumber just inserted
Date: 2005-02-03 22:16:33
Message-ID: 1107468993.16640.228.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, 2005-02-03 at 16:16, lorid wrote:
> I could have sworn I kept a copy of prior emails that discussed how to
> get back a value that was just inserted into a autonumber (or in
> postgresql case a sequence number)

If you know the name of the sequence the number came from you can use
currval():

insert into table1 (info) values ('abc');
select currval('table1seq');

Assuming table1seq is the name of the sequence here.

In 8.0 there's a function to do this (I'm not sure of the name, but a
quick search of the 8.0 docs should turn it up.)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Sean Davis 2005-02-03 22:19:50 Re: getting back autonumber just inserted
Previous Message lorid 2005-02-03 22:16:03 getting back autonumber just inserted