On 1/27/15 12:58 PM, Pavel Stehule wrote:
> postgres=# select array(select unnest('{{{1,2},{3,4}},{{5,6},{7,8}}}'::int[]));
> array
> -------------------
> {1,2,3,4,5,6,7,8}
> (1 row)
>
> so it generate pairs {1,2}{3,4},{5,6},{7,8}
>
>
> I fixed situation when array has not enough elements.
>
> More tests, simple doc
Hrm, this wasn't what I was expecting:
+ select foreach_test_ab(array[1,2,3,4]);
+ NOTICE: a: 1, b: 2
+ NOTICE: a: 3, b: 4
I was expecting that foreach a,b array would be expecting something in the array to have a dimension of 2. :(
I think this is bad, because this:
foreach_test_ab('{{1,2,3},{4,5,6}}'::int[]);
will give you 1,2; 3,4; 5,6. I don't see any way that that makes sense. Even if it did make sense, I'm more concerned
thatadding this will seriously paint us into a corner when it comes to the (to me) more rational case of returning
{1,2,3},{4,5,6}.
I think we need to think some more about this, at least to make sure we're not painting ourselves into a corner for
moreappropriate array iteration.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com