Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 034BE1337999 for ; Sun, 19 Sep 2010 20:04:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 35255-09 for ; Sun, 19 Sep 2010 23:04:21 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id E861E1337B2A for ; Sun, 19 Sep 2010 20:04:20 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OxSvg-0001Bv-L6 for pgsql-sql@postgresql.org; Mon, 20 Sep 2010 01:04:16 +0200 Received: from vpn-global-dhcp1-100.ethz.ch ([129.132.208.100]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 20 Sep 2010 01:04:16 +0200 Received: from roederja by vpn-global-dhcp1-100.ethz.ch with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 20 Sep 2010 01:04:16 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: =?UTF-8?B?SmFubiBSw7ZkZXI=?= Subject: Re: Table returning functions Date: Mon, 20 Sep 2010 01:04:07 +0200 Lines: 54 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: vpn-global-dhcp1-100.ethz.ch User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2 In-Reply-To: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/51 X-Sequence-Number: 34582 Ok I now know that it really seems to do what I expected. But I still wonder what it does if I use two functions f() and g() that return a different number of rows. I'm guessing a query such as SELECT id, (f(id)).a, (g(id)).b when f returns 3 rows and g returns two row would yield something like this: id | a1 | b1 id | a2 | b2 id | a3 | I haven't tried this, so it could be something completely different. In any case I think this should be documented. Jann Am 08.09.10 15:35, schrieb Jann Röder: > Hi, > I have a question which does not seem to be covered in the > documentation: I have a function f(i) that returns a table with three > columns (a, b, c). > > In the documentation > (http://www.postgresql.org/docs/8.4/interactive/xfunc-sql.html#XFUNC-SQL-FUNCTIONS-RETURNING-SET) > it says that (even though deprecated) you can call such functions in a > SELECT clause like so: > > SELECT id, f(id) FROM some_table . > > This will give me a two column table that looks like this: > > id | (a, b, c) > > However since I want a 4 column table like this > id | a | b | c > > , I do this instead: > > SELECT id, (f(id)).a, (f(id)).b, (f(id)).c FROM some_table. > > However I'm not quite sure if this really gives me what I want (i.e. the > same as in the first query only with the tuple elements as separate > columns). > > Of course I'm open to suggestions on how to do this more elegantly and > also how one can do something like this without using the deprecated > feature of calling a set returning function in SELECT. > > Jann > >