Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 66FF9B5DBE7 for ; Fri, 20 May 2011 16:43:58 -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 09663-05 for ; Fri, 20 May 2011 19:43:47 +0000 (UTC) X-Greylist: delayed 00:30:00.202934 by SQLgrey-1.7.6 Received: from mta6.srv.hcvlny.cv.net (mta6.srv.hcvlny.cv.net [167.206.4.212]) by mail.postgresql.org (Postfix) with ESMTP id 5ADF6B5D8B2 for ; Fri, 20 May 2011 16:43:47 -0300 (ADT) Received: from [192.168.1.143] (ool-addcf95d.static.optonline.net [173.220.249.93]) by mta6.srv.hcvlny.cv.net (Sun Java System Messaging Server 6.2-9.20 (built Jul 15 2010)) with ESMTPA id <0LLI00IA8DEWJK40@mta6.srv.hcvlny.cv.net> for pgsql-sql@postgresql.org; Fri, 20 May 2011 15:13:46 -0400 (EDT) Date: Fri, 20 May 2011 15:13:27 -0400 From: Karl Koster Subject: unnest in SELECT To: pgsql-sql@postgresql.org Message-id: <4DD6BD57.1080109@kdresources.com> 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/123 X-Sequence-Number: 35407 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