Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 12450B5D832 for ; Sat, 21 May 2011 03:59:00 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 05258-01 for ; Sat, 21 May 2011 06:58:53 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mailout02.ims-firmen.de (mailout02.ims-firmen.de [213.174.32.97]) by mail.postgresql.org (Postfix) with ESMTP id 148E3B5D80A for ; Sat, 21 May 2011 03:58:52 -0300 (ADT) Received: from [192.168.1.111] (helo=mi2) by mailout02.ims-firmen.de with esmtp (envelope-from ) id 1QNg9C-0007xW-Sm for pgsql-sql@postgresql.org; Sat, 21 May 2011 08:58:50 +0200 Received: from [87.170.217.2] (helo=a-kretschmer.de) by mi2 with esmtpsa (TLSv1:AES256-SHA:256) (envelope-from ) id 1QNg9C-0002Xb-N1 for pgsql-sql@postgresql.org; Sat, 21 May 2011 08:58:50 +0200 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1QNg9B-0001X3-6b for pgsql-sql@postgresql.org; Sat, 21 May 2011 08:58:49 +0200 Date: Sat, 21 May 2011 08:58:49 +0200 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: unnest in SELECT Message-ID: <20110521065849.GA5587@tux> References: <4DD6C4CD.40406@optonline.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4DD6C4CD.40406@optonline.net> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) 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/121 X-Sequence-Number: 35405 Karl Koster wrote: > 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? Yes. It's the same as: test=# select 1 as a where a = 2; ERROR: column "a" does not exist LINE 1: select 1 as a where a = 2; in other words: the column a is unknown for the where-condition at this time. > > 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. Yeah, it's a cross-join. Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknown) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°