From: Andreas Kretschmer <akretschmer@spamfence.net>
To: pgsql-sql@postgresql.org
Subject: Re: unnest in SELECT
Date: Sat, 21 May 2011 08:58:49 +0200
Message-ID: <20110521065849.GA5587@tux> (raw)
In-Reply-To: <4DD6C4CD.40406@optonline.net>
References: <4DD6C4CD.40406@optonline.net>
Karl Koster <klkoster@optonline.net> 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°
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: akretschmer@spamfence.net
Subject: Re: unnest in SELECT
In-Reply-To: <20110521065849.GA5587@tux>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox