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 wrote: > Gavin Flower 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 function

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

2013-03-28 Thread Jasen Betts
On 2013-03-27, Ken Tanzer 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 lengths, so that this

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 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 nu

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

2013-03-27 Thread Ian Lawrence Barwick
2013/3/27 Tom Lane : > Gavin Flower 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 num

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

2013-03-27 Thread Tom Lane
Gavin Flower 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 rows you get is the leas

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 (row_number)

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 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 c: testdb=# DE

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

2013-03-27 Thread Ian Lawrence Barwick
2013/3/27 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 > -+

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 |

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

2013-03-26 Thread Ian Lawrence Barwick
2013/3/27 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']); > >