unnest in SELECT

From: Karl Koster <kkoster(at)kdresources(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: unnest in SELECT
Date: 2011-05-20 19:13:27
Message-ID: 4DD6BD57.1080109@kdresources.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Karl Koster 2011-05-20 19:45:17 unnest in SELECT
Previous Message Emi Lu 2011-05-19 17:48:10 Re: column type for pdf file