Re: unnest in SELECT - Mailing list pgsql-sql

From Andreas Kretschmer
Subject Re: unnest in SELECT
Date
Msg-id 20110521065849.GA5587@tux
Whole thread Raw
In response to unnest in SELECT  (Karl Koster <klkoster@optonline.net>)
List pgsql-sql
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°


pgsql-sql by date:

Previous
From: Karl Koster
Date:
Subject: unnest in SELECT
Next
From: Gavin Baumanis
Date:
Subject: Which version of PostgreSQL should I use.