From: | Jack Christensen <jack(at)jncsoftware(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Set returning functions in select column list |
Date: | 2012-02-17 00:34:49 |
Message-ID: | 4F3DA0A9.8020402@jncsoftware.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
* Apologies if anyone receives this twice. I previously sent it from
another address and it did not appear to go through.
Can someone explain how set returning functions in a select clause work?
It seems that it is doing some sort of implicit cross join.
deliverance_development=# select id, generate_series(1, 3) from users;
id | generate_series
----+-----------------
0 | 1
0 | 2
0 | 3
1 | 1
1 | 2
1 | 3
(6 rows)
But if multiple set returning functions that return the same number of
rows are in the same select it doesn't further cross join it.
deliverance_development=# select id, generate_series(1, 3),
generate_series(4, 6) from users;
id | generate_series | generate_series
----+-----------------+-----------------
0 | 1 | 4
0 | 2 | 5
0 | 3 | 6
1 | 1 | 4
1 | 2 | 5
1 | 3 | 6
(6 rows)
But if the set returning functions return a different number of rows
then it goes back to a cross join.
deliverance_development=# select id, generate_series(1, 3),
generate_series(4, 5) from users;
id | generate_series | generate_series
----+-----------------+-----------------
0 | 1 | 4
0 | 2 | 5
0 | 3 | 4
0 | 1 | 5
0 | 2 | 4
0 | 3 | 5
1 | 1 | 4
1 | 2 | 5
1 | 3 | 4
1 | 1 | 5
1 | 2 | 4
1 | 3 | 5
(12 rows)
I really don't understand what is going on here. I have checked Google
and the PostgreSQL docs, but it appears either I do not know the key
words to search for or it is sparsely documented.
Jack
From | Date | Subject | |
---|---|---|---|
Next Message | Steve Crawford | 2012-02-17 00:45:36 | Re: Fwd: Re: Dynamic update of a date field |
Previous Message | Adrian Klaver | 2012-02-16 23:19:37 | Re: running multiple versions |