X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C4E538B9F91 for ; Thu, 3 Feb 2005 22:16:37 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 06287-02 for ; Thu, 3 Feb 2005 22:16:33 +0000 (GMT) Received: from koolancexeon.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by svr1.postgresql.org (Postfix) with ESMTP id 1059C8B9F84 for ; Thu, 3 Feb 2005 22:16:34 +0000 (GMT) Received: mail.g2switchworks.com 10.10.1.8 from 10.10.1.37 10.10.1.37 via HTTP with MS-WebStorage 6.5.6944 Received: from state.g2switchworks.com by mail.g2switchworks.com; 03 Feb 2005 16:16:33 -0600 Subject: Re: getting back autonumber just inserted From: Scott Marlowe To: lorid Cc: pgsql-sql@postgresql.org In-Reply-To: <4202A2A3.7070707@dri.edu> References: <5d14ecf90410162019443dc355@mail.gmail.com> <4202A2A3.7070707@dri.edu> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1107468993.16640.228.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Thu, 03 Feb 2005 16:16:33 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200502/80 X-Sequence-Number: 20191 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.)