Re: array_length(anyarray) - Mailing list pgsql-hackers

From Merlin Moncure
Subject Re: array_length(anyarray)
Date
Msg-id CAHyXU0wu81O8ypkC6+2e_OH0bJgDFfvJtrsKaRRtEmCreZ+xeg@mail.gmail.com
Whole thread Raw
In response to Re: array_length(anyarray)  (Marko Tiikkaja <marko@joh.to>)
Responses Re: array_length(anyarray)  (Florian Pflug <fgp@phlo.org>)
List pgsql-hackers
On Fri, Jan 10, 2014 at 3:52 AM, Marko Tiikkaja <marko@joh.to> wrote:
> On 1/10/14, 10:41 AM, Merlin Moncure wrote:
>>
>> What's needed for better iteration support (IMO)
>> is a function that does what unnest does but returns an array on
>> indexes (one per dimsension) -- a generalization of the
>> _pg_expandarray function.  Lets' say 'unnest_dims'.
>
>
> So  unnest_dims('{{1,2},{3,4}}'::int[])  would return  VALUES (1,
> '{1,2}'::int[]), (2, '{3,4}'::int[])?  If so, then yes, that's a
> functionality I've considered us to have been missing for a long time.

not quite.  it returns int[], anyelement: so, using your example, you'd get:

[1,1], 1
[1,2], 2
[2,1], 3
[2,2], 4

like unnest() it would fully decompose the array do individual
elements.  what you have above slices the array which is useful,but
probably shouldn't live under the 'unnest' name -- perhaps 'slice'.
Pavel added it to pl/pgsql under the FOREACH syntax (FYI).

merlin



pgsql-hackers by date:

Previous
From: Marko Tiikkaja
Date:
Subject: Re: array_length(anyarray)
Next
From: Gabriele Bartolini
Date:
Subject: Re: [PATCH] Relocation of tablespaces in pg_basebackup