pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Marlowe <smarlowe@g2switchworks.com>
To: lorid <lorid@dri.edu>
Cc: pgsql-sql@postgresql.org
Subject: Re: getting back autonumber just inserted
Date: Thu, 03 Feb 2005 16:16:33 -0600
Message-ID: <1107468993.16640.228.camel@state.g2switchworks.com> (raw)
In-Reply-To: <4202A2A3.7070707@dri.edu>
References: <5d14ecf90410162019443dc355@mail.gmail.com>
	<4202A2A3.7070707@dri.edu>

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.)



view thread (30+ messages)  latest in thread

Message-ID: <1107468993.16640.228.camel@state.g2switchworks.com>
Permalink:  ../1107468993.16640.228.camel@state.g2switchworks.com/
Also on:    postgresql.org/message-id/1107468993.16640.228.camel@state.g2switchworks.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: smarlowe@g2switchworks.com, lorid@dri.edu
  Subject: Re: getting back autonumber just inserted
  In-Reply-To: <1107468993.16640.228.camel@state.g2switchworks.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox