Re: unnest on multi-dimensional arrays

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: bricklen <bricklen(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: unnest on multi-dimensional arrays
Date: 2013-11-28 16:03:37
Message-ID: CAFj8pRBVbnV9cWUobug+1Wwg9+VhuXK1tSr6yJxa1TwXzwGd0A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2013/11/28 bricklen <bricklen(at)gmail(dot)com>

> On Wed, Nov 27, 2013 at 11:28 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>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 LOOP;
>> RETURN;
>> END;
>> $function$;
>> CREATE FUNCTION
>>
>> postgres=# select reduce_dim(array[array[1, 2], array[2, 3]]);
>> reduce_dim
>> ------------
>> {1,2}
>> {2,3}
>> (2 rows)
>>
>
> Hi Pavel,
>
> I hope you don't mind, I took the liberty of adding your nifty function to
> the Postgresql Wiki at
> https://wiki.postgresql.org/wiki/Unnest_multidimensional_array
>
> Feel free to edit directly or suggest any changes to it.
>

+1

Pavel

>
> Cheers,
>
> Bricklen
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve.Toutant 2013-11-28 16:25:41 query creates a huge toast tables
Previous Message bricklen 2013-11-28 16:01:26 Re: unnest on multi-dimensional arrays