Re: [GENERAL] unnest on multi-dimensional arrays

2013-12-03 Thread Pavel Stehule
2013/12/2 Tom Lane > Zev Benjamin writes: > > This actually looks to mostly be a parser limitation: > > Well, you'd also need some execution-time infrastructure to evaluate an > expression, if we allowed one there, but I agree it wouldn't be a > tremendously complicated patch. We'd just not for

Re: [GENERAL] unnest on multi-dimensional arrays

2013-12-02 Thread Tom Lane
Zev Benjamin writes: > This actually looks to mostly be a parser limitation: Well, you'd also need some execution-time infrastructure to evaluate an expression, if we allowed one there, but I agree it wouldn't be a tremendously complicated patch. We'd just not foreseen a good reason to support a

Re: [GENERAL] unnest on multi-dimensional arrays

2013-12-02 Thread Zev Benjamin
This actually looks to mostly be a parser limitation: foreach_slice : { $$ = 0; } | K_SLICE ICONST

Re: [GENERAL] unnest on multi-dimensional arrays

2013-12-02 Thread Pavel Stehule
2013/12/2 Zev Benjamin > Hrm. Conceptually, I think you actually want something like: > > > CREATE OR REPLACE FUNCTION public.reduce_dim(anyarray) > RETURNS SETOF anyarray > LANGUAGE plpgsql > AS $function$ > DECLARE > s $1%type; > d int; > BEGIN > d := array_ndims($1) - 1; > FOREACH s

Re: [GENERAL] unnest on multi-dimensional arrays

2013-12-02 Thread Zev Benjamin
Hrm. Conceptually, I think you actually want something like: CREATE OR REPLACE FUNCTION public.reduce_dim(anyarray) RETURNS SETOF anyarray LANGUAGE plpgsql AS $function$ DECLARE s $1%type; d int; BEGIN d := array_ndims($1) - 1; FOREACH s SLICE d IN ARRAY $1 LOOP RETURN NEXT s;

Re: [GENERAL] unnest on multi-dimensional arrays

2013-12-02 Thread Zev Benjamin
Thanks for the explanation and examples! Zev On 11/28/2013 10:03 AM, Tom Lane wrote: David Johnston writes: Zev Benjamin wrote It appears that unnest, when called on a multi-dimensional array, effectively flattens the array first. For example: ... Multidimensional arrays do have shortco

[GENERAL] unnest on multi-dimensional arrays

2013-11-30 Thread Zev Benjamin
It appears that unnest, when called on a multi-dimensional array, effectively flattens the array first. For example: => select * from unnest(array[array[1, 2], array[2, 3]]); unnest 1 2 2 3 (4 rows) while I would have expect something like the following: => s

Re: [GENERAL] unnest on multi-dimensional arrays

2013-11-29 Thread Glyn Astill
> From: Pavel Stehule >To: bricklen >Cc: "pgsql-general@postgresql.org" >Sent: Thursday, 28 November 2013, 16:03 >Subject: Re: [GENERAL] unnest on multi-dimensional arrays > >2013/11/28 bricklen > >On Wed, Nov 27, 2013 at 11:28 PM, Pavel Stehule &

Re: [GENERAL] unnest on multi-dimensional arrays

2013-11-28 Thread Pavel Stehule
2013/11/28 bricklen > On Wed, Nov 27, 2013 at 11:28 PM, Pavel Stehule > wrote: > >> Hello >> >> postgres=# CREATE OR REPLACE FUNCTION public.reduce_dim(anyarray) >> RETURNS SETOF anyarray >> LANGUAGE plpgsql >> AS $function$ >> DECLARE s $1%type; >> BEGIN >> FOREACH s SLICE 1 IN ARRAY $1 LO

Re: [GENERAL] unnest on multi-dimensional arrays

2013-11-28 Thread bricklen
On Wed, Nov 27, 2013 at 11:28 PM, Pavel Stehule wrote: > Hello > > postgres=# CREATE OR REPLACE FUNCTION public.reduce_dim(anyarray) > RETURNS SETOF anyarray > LANGUAGE plpgsql > AS $function$ > DECLARE s $1%type; > BEGIN > FOREACH s SLICE 1 IN ARRAY $1 LOOP > RETURN NEXT s; > END LOO

Re: [GENERAL] unnest on multi-dimensional arrays

2013-11-28 Thread Tom Lane
David Johnston writes: > Zev Benjamin wrote >> It appears that unnest, when called on a multi-dimensional array, >> effectively flattens the array first. For example: ... > Multidimensional arrays do have shortcomings in the current implementation > of which this is one. I'm not sure, though,

Re: [GENERAL] unnest on multi-dimensional arrays

2013-11-27 Thread David Johnston
Zev Benjamin wrote > It appears that unnest, when called on a multi-dimensional array, > effectively flattens the array first. For example: > > => select * from unnest(array[array[1, 2], array[2, 3]]); > unnest > >1 >2 >2 >3 > (4 rows) > > while I woul

Re: [GENERAL] unnest on multi-dimensional arrays

2013-11-27 Thread Pavel Stehule
Hello postgres=# CREATE OR REPLACE FUNCTION public.reduce_dim(anyarray) RETURNS SETOF anyarray LANGUAGE plpgsql AS $function$ DECLARE s $1%type; BEGIN FOREACH s SLICE 1 IN ARRAY $1 LOOP RETURN NEXT s; END LOOP; RETURN; END; $function$; CREATE FUNCTION postgres=# select reduce_dim(arr

[GENERAL] unnest on multi-dimensional arrays

2013-11-27 Thread Zev Benjamin
It appears that unnest, when called on a multi-dimensional array, effectively flattens the array first. For example: => select * from unnest(array[array[1, 2], array[2, 3]]); unnest 1 2 2 3 (4 rows) while I would have expect something like the following: => s