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
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
This actually looks to mostly be a parser limitation:
foreach_slice :
{
$$ = 0;
}
| K_SLICE ICONST
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
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;
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
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
> 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
&
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
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
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,
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
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
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
14 matches
Mail list logo