Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 7BA769F9A02 for ; Sat, 10 Nov 2007 17:04:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 97144-08 for ; Sat, 10 Nov 2007 17:04:10 -0400 (AST) Received: from oxford.xeocode.com (unknown [87.127.95.196]) by postgresql.org (Postfix) with ESMTP id 2C7FE9F99FC for ; Sat, 10 Nov 2007 17:04:09 -0400 (AST) Received: from localhost.enta.net ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.67) (envelope-from ) id 1IqxUs-00007b-HV; Sat, 10 Nov 2007 21:04:06 +0000 To: "Tom Lane" Cc: "Michele Petrazzo - Unipex srl" , "Pgsql-Sql" Subject: Re: functions are returns columns In-Reply-To: <19335.1194723995@sss.pgh.pa.us> (Tom Lane's message of "Sat\, 10 Nov 2007 14\:46\:35 -0500") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX" 47657) References: <4734B921.5050704@unipex.it> <162867790711091235i7e77abcch27731d91285949b6@mail.gmail.com> <4735EC6F.5050908@unipex.it> <878x55dhau.fsf@oxford.xeocode.com> <19335.1194723995@sss.pgh.pa.us> From: Gregory Stark Organization: EnterpriseDB Date: Sat, 10 Nov 2007 21:04:06 +0000 Message-ID: <874pftdd89.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/41 X-Sequence-Number: 29569 "Tom Lane" writes: > Gregory Stark writes: >> You're almost there: > >> CREATE FUNCTION getfoo (IN int, OUT int, OUT int) returns setof record(int,int) AS $$ >> SELECT fooid, foosubid FROM foo WHERE fooid = $1; >> $$ LANGUAGE SQL; > > Not quite --- it's just "returns setof record". The output column types > are defined by the OUT parameters. The only reason you need the returns > clause is to have a place to stick the "setof" specification ... ok... I did test my example before posting it: postgres=# postgres=# CREATE or replace FUNCTION getfoo (IN int, OUT int, OUT int) returns setof record(int,int)AS $$ SELECT 1,2 union all select 2,3; $$ LANGUAGE SQL; postgres$# postgres$# CREATE FUNCTION postgres=# postgres=# select * from getfoo(1); column1 | column2 ---------+--------- 1 | 2 2 | 3 (2 rows) -- Gregory Stark EnterpriseDB http://www.enterprisedb.com Ask me about EnterpriseDB's 24x7 Postgres support!