Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id E449E6328D9 for ; Thu, 18 Mar 2010 12:53:13 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 69904-01 for ; Thu, 18 Mar 2010 15:53:01 +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 20645632330 for ; Thu, 18 Mar 2010 12:53:02 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1NsI1s-0000lF-Lr for pgsql-docs@postgresql.org; Thu, 18 Mar 2010 16:53:00 +0100 Received: from p548e4a2e.dip.t-dialin.net ([84.142.74.46]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 18 Mar 2010 16:53:00 +0100 Received: from tim by p548e4a2e.dip.t-dialin.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 18 Mar 2010 16:53:00 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: pgsql-docs@postgresql.org To: pgsql-docs@postgresql.org From: Tim Landscheidt Subject: [PATCH] Explain generate_subscripts() more clearly Date: Thu, 18 Mar 2010 15:52:31 +0000 Organization: Lines: 59 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: p548e4a2e.dip.t-dialin.net Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:zd19zC2ZWg/ngIspiDE3ygLZJiQ= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201003/14 X-Sequence-Number: 5379 --=-=-= Hi, the current documentation on generate_subscripts() uses a "rectangular" example, i. e. where both arrays in question have the same length (that is furthermore equal to the num- ber of arrays, a "square" example so to speak :-)). To point out that generate_subscripts () can be used for more complex cases as well, please find attached patch. Tim --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=generate-subscripts-doc.patch Content-Description: Patch to illustrate generate_subscripts ()'s behaviour more clearly. diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 3419440..2677db9 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -11427,21 +11427,22 @@ select generate_subscripts('{NULL,1,NULL,2}'::int[], 1) as s; -- presenting an array, the subscript and the subscripted -- value requires a subquery select * from arrays; - a --------------------- + a +--------------- {-1,-2} - {100,200} -(2 rows) + {100,200,300} +(2 Zeilen) select a as array, s as subscript, a[s] as value from (select generate_subscripts(a, 1) as s, a from arrays) foo; - array | subscript | value ------------+-----------+------- - {-1,-2} | 1 | -1 - {-1,-2} | 2 | -2 - {100,200} | 1 | 100 - {100,200} | 2 | 200 -(4 rows) + array | subscript | value +---------------+-----------+------- + {-1,-2} | 1 | -1 + {-1,-2} | 2 | -2 + {100,200,300} | 1 | 100 + {100,200,300} | 2 | 200 + {100,200,300} | 3 | 300 +(5 Zeilen) -- unnest a 2D array create or replace function unnest2(anyarray) --=-=-=--