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 0DD92D6D93 for ; Sat, 27 Aug 2005 09:53:36 -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 27506-01 for ; Sat, 27 Aug 2005 12:53:33 +0000 (GMT) Received: from viefep17-int.chello.at (unknown [213.46.255.24]) by svr1.postgresql.org (Postfix) with ESMTP id 27550D7C51 for ; Sat, 27 Aug 2005 09:53:31 -0300 (ADT) Received: from OTTO ([213.222.172.216]) by viefep17-int.chello.at (InterMail vM.6.01.04.04 201-2131-118-104-20050224) with SMTP id <20050827125333.TTUB1234.viefep17-int.chello.at@OTTO>; Sat, 27 Aug 2005 14:53:33 +0200 Message-ID: <005401c5ab06$54878c10$6b00a8c0@OTTO> From: =?ISO-8859-1?Q?Havasv=F6lgyi_Ott=F3?= To: "Matt A." , References: <20050821195627.8524.qmail@web35209.mail.mud.yahoo.com> Subject: Re: returning inserted id Date: Sat, 27 Aug 2005 14:53:32 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="ISO-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=-0.085 required=5 tests=[AWL=-0.085] X-Spam-Level: X-Archive-Number: 200508/261 X-Sequence-Number: 22489 Matt, This is how you can do it: create function person_ins(_name text) returns integer language plpgsql as $$ declare insert_id integer; begin insert into person (name) values(_name); select into insert_id currval('person_id_seq'); return insert_id; end; $$; Or perhaps even better: you return the whole inserted row (in 8.1 with INOUT parameters): create function person_ins(_name text) returns person language plpgsql as $$ declare inserted_row person; begin insert into person (name) values(_name); select into inserted_row * from person where id=currval('person_id_seq'); return inserted_row; end; $$; Hope there is no syntax error. Best Regards, Otto ----- Original Message ----- From: "Matt A." To: Sent: Sunday, August 21, 2005 9:56 PM Subject: [SQL] returning inserted id > 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? > > Thanks, > Matt > > > > ____________________________________________________ > Start your day with Yahoo! - make it your home page > http://www.yahoo.com/r/hs > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq > >