Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 00287C24694 for ; Fri, 30 Dec 2011 10:48:52 -0400 (AST) Received: from lo.gmane.org ([80.91.229.12]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RgdlK-0003tW-Gl for pgsql-sql@postgresql.org; Fri, 30 Dec 2011 14:48:51 +0000 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Rgdl7-00047p-3N for pgsql-sql@postgresql.org; Fri, 30 Dec 2011 15:48:37 +0100 Received: from host-188-174-161-46.customer.m-online.net ([188.174.161.46]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 30 Dec 2011 15:48:37 +0100 Received: from spam_eater by host-188-174-161-46.customer.m-online.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 30 Dec 2011 15:48:37 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Thomas Kellerer Subject: Re: avoid the creating the type for setof Date: Fri, 30 Dec 2011 15:48:30 +0100 Lines: 33 Message-ID: References: <1762087.ynHxkPSFx3@linux-12> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: host-188-174-161-46.customer.m-online.net User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 In-Reply-To: <1762087.ynHxkPSFx3@linux-12> X-Pg-Spam-Score: -5.5 (-----) X-Archive-Number: 201112/98 X-Sequence-Number: 36159 John Fabiani wrote on 30.12.2011 15:26: > Hi, > I recall somewhere I saw a simple plpgsql function that returned a table with > more than one record that did not use a defined type or a temp table ( at > least I think I did). Is it possible to create such a function that will > return more than one record and not require a record type or temp table? > > something like > > return setof record as > return query select ... > > return Sure: create or replace function returns table (f1 text, f2 integer) as $$ select col1, col2 from some table; $$ language sql; If you are using PL/pgSQL you need to use "RETURN QUERY SELECT ..." inside the function. For more details see the examples in the manual: http://www.postgresql.org/docs/current/static/sql-createfunction.html http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-STATEMENTS-RETURNING Thomas