Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 05EFD9F9277 for ; Fri, 9 Nov 2007 15:46:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 26566-03 for ; Fri, 9 Nov 2007 15:46:41 -0400 (AST) Received: from relay0.fra.interoute.net (relay0.fra.interoute.net [212.23.33.89]) by postgresql.org (Postfix) with ESMTP id AD6379F9245 for ; Fri, 9 Nov 2007 15:46:49 -0400 (AST) Received: from debian-srv (unknown [89.202.235.9]) by relay0.fra.interoute.net (Postfix) with ESMTP id 5E800B8B4 for ; Fri, 9 Nov 2007 19:46:42 +0000 (UTC) Received: from [192.168.1.103] (michele [192.168.1.103]) by debian-srv (Postfix) with ESMTP id 3A78070316 for ; Fri, 9 Nov 2007 20:47:06 +0100 (CET) Message-ID: <4734B921.5050704@unipex.it> Date: Fri, 09 Nov 2007 20:46:41 +0100 From: Michele Petrazzo - Unipex srl User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1b1) Gecko/20060724 Thunderbird/2.0a1 Mnenhy/0.7.4.0 MIME-Version: 1.0 To: Pgsql-Sql Subject: functions are returns columns Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/36 X-Sequence-Number: 29564 Hi all. I want that a function return a table rows (like the doc says at 33.4.4. SQL Functions as Table Sources), but I want the a function return only a few cols, so the same that I select into the func. Modifying the doc example: CREATE TABLE foo (fooid int, foosubid int, fooname text); INSERT INTO foo VALUES (1, 1, 'Joe'); INSERT INTO foo VALUES (1, 2, 'Ed'); INSERT INTO foo VALUES (2, 1, 'Mary'); CREATE FUNCTION getfoo(int) RETURNS foo AS $$ SELECT fooid, foosubid FROM foo WHERE fooid = $1; $$ LANGUAGE SQL; This give me an error: ERROR: return type mismatch in function declared to return foo DETAIL: Final SELECT returns too few columns. CONTEXT: SQL function "getfoo" So, how do it? Thanks, Michele