Re: unnest on multi-dimensional arrays - Mailing list pgsql-general

From bricklen
Subject Re: unnest on multi-dimensional arrays
Date
Msg-id CAGrpgQ95-U-xYSfma2W3yO_fXjVWYiJKbPdXe+F7z1sCU8icGQ@mail.gmail.com
Whole thread Raw
In response to Re: unnest on multi-dimensional arrays  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: unnest on multi-dimensional arrays
List pgsql-general
On Wed, Nov 27, 2013 at 11:28 PM, Pavel Stehule <pavel.stehule@gmail.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
Feel free to edit directly or suggest any changes to it.

Cheers,

Bricklen

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: unnest on multi-dimensional arrays
Next
From: Pavel Stehule
Date:
Subject: Re: unnest on multi-dimensional arrays