X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CFE0BD7F15 for ; Sat, 27 Aug 2005 03:15:22 -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 42692-04 for ; Sat, 27 Aug 2005 06:15:18 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.197.194]) by svr1.postgresql.org (Postfix) with SMTP id DD3CDD7F03 for ; Sat, 27 Aug 2005 03:15:16 -0300 (ADT) Received: (qmail 27850 invoked by uid 500); 27 Aug 2005 06:14:55 -0000 Date: Sat, 27 Aug 2005 01:14:55 -0500 From: Bruno Wolff III To: "Matt A." Cc: pgsql-sql@postgresql.org Subject: Re: returning inserted id Message-ID: <20050827061455.GA27248@wolff.to> Mail-Followup-To: Bruno Wolff III , "Matt A." , pgsql-sql@postgresql.org References: <20050821195627.8524.qmail@web35209.mail.mud.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050821195627.8524.qmail@web35209.mail.mud.yahoo.com> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200508/258 X-Sequence-Number: 22486 On Sun, Aug 21, 2005 at 12:56:27 -0700, "Matt A." wrote: > this may have been asked a thousand times but i > haven't found a standard answer... > > > MSSQL > set nocount on > insert into (column) values (value) > select identityid = @@identity > set nocount off > > > POSTGRESQL > *cricket cricket* :) > > > How is this done? By a trigger function? Or is it > natively supported? Could I get an example on how to > do it too? Use a serial type for the column and use currval to get the last value assign to the corresponding sequence in the current session. You probably want to read the documentation section on sequences. http://candle.pha.pa.us/main/writings/pgsql/sgml/functions-sequence.html http://candle.pha.pa.us/main/writings/pgsql/sgml/datatype.html#DATATYPE-INT