X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B9FB55294C for ; Wed, 17 Aug 2005 01:38:23 -0300 (ADT) 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 26170-03 for ; Wed, 17 Aug 2005 04:38:22 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.197.194]) by svr1.postgresql.org (Postfix) with SMTP id E333952910 for ; Wed, 17 Aug 2005 01:38:21 -0300 (ADT) Received: (qmail 940 invoked by uid 500); 17 Aug 2005 04:40:06 -0000 Date: Tue, 16 Aug 2005 23:40:06 -0500 From: Bruno Wolff III To: "josh@segrestfarms.com" Cc: pgsql-admin@postgresql.org Subject: Re: SQL Help - Obtaining ID of record INSERTED Message-ID: <20050817044006.GA32756@wolff.to> Mail-Followup-To: Bruno Wolff III , "josh@segrestfarms.com" , pgsql-admin@postgresql.org References: <430255F0.7060500@segrestfarms.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <430255F0.7060500@segrestfarms.com> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.241 required=5 tests=[AWL=-0.229, TO_ADDRESS_EQ_REAL=0.47] X-Spam-Level: X-Archive-Number: 200508/209 X-Sequence-Number: 18528 On Tue, Aug 16, 2005 at 17:09:04 -0400, "josh@segrestfarms.com" wrote: > Greetings. > > INSERT INTO > orderstemp (customerid,datecreated) > VALUES > ('5443','8/16/2005 12:00PM') > > The table orderstemp has a unique identifier field, orderid (of type > SERIAL). > > How can I obtain the orderid of the record inserted in the INSERT INTO > statement in postgresql? > > MSSQL does it like this: > > INSERT INTO > orderstemp (customerid,datecreated) > VALUES > ('5443','8/16/2005 12:00PM') > SELECT @@identity as orderid > > but this doens't work in postgresql. > > Any ideas? Thanks in advance. You want to use currval. In 8.0 you would use: SELECT currval(pg_get_serial_sequence('orderstemp', 'orderid'));