Re: Understanding behavior of SELECT with multiple unnested columns
От | Ian Lawrence Barwick |
---|---|
Тема | Re: Understanding behavior of SELECT with multiple unnested columns |
Дата | |
Msg-id | CAB8KJ=iENNUc4P6EJQCuq+3EU58EfA6_8A9s8Q=tN0fgJiLCpw@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Understanding behavior of SELECT with multiple unnested columns (Ken Tanzer <ken.tanzer@gmail.com>) |
Ответы |
Re: Understanding behavior of SELECT with multiple unnested
columns
|
Список | pgsql-general |
2013/3/27 Ken Tanzer <ken.tanzer@gmail.com>
Basically you are getting Cartesian joins on the row output of
unnest()Well that's what I expected too. Except look at this example, after you delete c:testdb=# DELETE FROM t2 where val='c';DELETE 1testdb=# SELECT * from t1, t2;val | val-----+-----1 | a1 | b2 | a2 | b(4 rows)And compare to:SELECT unnest(array[1,2]),unnest(array['a','b']);unnest | unnest--------+--------1 | a2 | b(2 rows)You can see they are not the same!
Ah yes, what I suggested is actually the equivalent to
SELECT * FROM unnest(array[1,2]) u1,unnest(array['a','b']) u2;
SELECT * FROM unnest(array[1,2]) u1,unnest(array['a','b']) u2;
I seem to recall seeing the explanation for this before, although I'll be
darned if I can remember what it is.
darned if I can remember what it is.
FWIW this happens with other functions returning SETOF:
testdb=# SELECT
testdb-# generate_series(1,2) x,
testdb-# generate_series(1,2) y;
x | y
---+---
1 | 1
2 | 2
(2 rows)
testdb=# SELECT
testdb-# generate_series(1,2) x,
testdb-# generate_series(1,3) y;
x | y
---+---
1 | 1
2 | 2
1 | 3
2 | 1
1 | 2
2 | 3
(6 rows)
testdb=# SELECT
testdb-# generate_series(1,2) x,
testdb-# generate_series(1,2) y;
x | y
---+---
1 | 1
2 | 2
(2 rows)
testdb=# SELECT
testdb-# generate_series(1,2) x,
testdb-# generate_series(1,3) y;
x | y
---+---
1 | 1
2 | 2
1 | 3
2 | 1
1 | 2
2 | 3
(6 rows)
Regards
Ian Barwick
Ian Barwick
В списке pgsql-general по дате отправления: