Re: [GENERAL] Understanding behavior of SELECT with multiple unnested columns

2013-03-29 Thread Merlin Moncure
On Wed, Mar 27, 2013 at 9:03 AM, Tom Lane t...@sss.pgh.pa.us wrote: Gavin Flower gavinflo...@archidevsys.co.nz writes: The rule appears to be, where N_x N_y are the number of entries returned for x y: N_result = is the smallest positive integer that has N_x N_y as factors. Right: if there

Re: [GENERAL] Understanding behavior of SELECT with multiple unnested columns

2013-03-28 Thread Gavin Flower
On 28/03/13 03:03, Tom Lane wrote: Gavin Flower gavinflo...@archidevsys.co.nz writes: The rule appears to be, where N_x N_y are the number of entries returned for x y: N_result = is the smallest positive integer that has N_x N_y as factors. Right: if there are multiple set-returning

Re: [GENERAL] Understanding behavior of SELECT with multiple unnested columns

2013-03-28 Thread Jasen Betts
On 2013-03-27, Ken Tanzer ken.tan...@gmail.com wrote: --047d7b5da657ecd54004d8e23a90 Content-Type: text/plain; charset=ISO-8859-1 I've been working on some queries involving multiple unnested columns. At first, I expected the number of rows returned would be the product of the array

[GENERAL] Understanding behavior of SELECT with multiple unnested columns

2013-03-27 Thread Ken Tanzer
I've been working on some queries involving multiple unnested columns. At first, I expected the number of rows returned would be the product of the array lengths, so that this query would return 4 rows: SELECT unnest2(array['a','b']),unnest2(array['1','2']); when in fact it returns 2: unnest2

Re: [GENERAL] Understanding behavior of SELECT with multiple unnested columns

2013-03-27 Thread Ian Lawrence Barwick
2013/3/27 Ken Tanzer ken.tan...@gmail.com I've been working on some queries involving multiple unnested columns. At first, I expected the number of rows returned would be the product of the array lengths, so that this query would return 4 rows: SELECT

Re: [GENERAL] Understanding behavior of SELECT with multiple unnested columns

2013-03-27 Thread Ken Tanzer
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 1 testdb=# SELECT * from t1, t2; val | val -+- 1 | a 1 | b 2 | a 2 | b

Re: [GENERAL] Understanding behavior of SELECT with multiple unnested columns

2013-03-27 Thread Ian Lawrence Barwick
2013/3/27 Ken Tanzer ken.tan...@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 1 testdb=# SELECT * from t1, t2; val | val

Re: [GENERAL] Understanding behavior of SELECT with multiple unnested columns

2013-03-27 Thread Gavin Flower
On 27/03/13 20:36, Ian Lawrence Barwick wrote: 2013/3/27 Ken Tanzer ken.tan...@gmail.com mailto:ken.tan...@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

Re: [GENERAL] Understanding behavior of SELECT with multiple unnested columns

2013-03-27 Thread Misa Simic
Hi, You can try: SELECT c1, c2 FROM ( WITH a AS ( SELECT row_number() OVER(),* FROM unnest(array['a','b', 'c', 'd']) c1 ), b AS ( SELECT row_number() OVER(),* FROM unnest(array['1','2', '3']) c2 ) SELECT * FROM a LEFT JOIN b USING (row_number) UNION SELECT * FROM a RIGHT JOIN b USING

Re: [GENERAL] Understanding behavior of SELECT with multiple unnested columns

2013-03-27 Thread Tom Lane
Gavin Flower gavinflo...@archidevsys.co.nz writes: The rule appears to be, where N_x N_y are the number of entries returned for x y: N_result = is the smallest positive integer that has N_x N_y as factors. Right: if there are multiple set-returning functions in a SELECT list, the number of

Re: [GENERAL] Understanding behavior of SELECT with multiple unnested columns

2013-03-27 Thread Ian Lawrence Barwick
2013/3/27 Tom Lane t...@sss.pgh.pa.us: Gavin Flower gavinflo...@archidevsys.co.nz writes: The rule appears to be, where N_x N_y are the number of entries returned for x y: N_result = is the smallest positive integer that has N_x N_y as factors. Right: if there are multiple set-returning