Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id ADF6AB5D832 for ; Fri, 20 May 2011 17:15:51 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 95617-10 for ; Fri, 20 May 2011 20:15:44 +0000 (UTC) X-Greylist: delayed 00:30:07.007898 by SQLgrey-1.7.6 Received: from mta3.srv.hcvlny.cv.net (mta3.srv.hcvlny.cv.net [167.206.4.198]) by mail.postgresql.org (Postfix) with ESMTP id E706EB5D801 for ; Fri, 20 May 2011 17:15:43 -0300 (ADT) Received: from [192.168.1.143] (ool-addcf95d.static.optonline.net [173.220.249.93]) by mta3.srv.hcvlny.cv.net (Sun Java System Messaging Server 6.2-8.04 (built Feb 28 2007)) with ESMTPA id <0LLI00BZPEVZQQ30@mta3.srv.hcvlny.cv.net> for pgsql-sql@postgresql.org; Fri, 20 May 2011 15:45:36 -0400 (EDT) Date: Fri, 20 May 2011 15:45:17 -0400 From: Karl Koster Subject: unnest in SELECT To: pgsql-sql@postgresql.org Message-id: <4DD6C4CD.40406@optonline.net> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201105/120 X-Sequence-Number: 35404 I have a couple of questions regarding unnest. 1) If I issue a select statement "select unnest(vector1) as v from some_table", I cannot seem to use the column alias v in a WHERE or HAVING clause. I can use it in an ORDER BY or GROUP by clause. Is this the way it is supposed to work? 2) If I issue a select statement "select unnest(vector1) as v1, unnest(vector2) as v2 from some_table" and vector1 has a length of 3 and vector2 has a length of 4, the result set will have 12 rows with the data of vector1 repeating 4 times and vector2 repeating 3 times. Shouldn't the content of the shorter array(s) simply be return null in it's respective column and the result set be the size of the longest array? Thanks, Karl