2007/10/18, Merlin Moncure <[EMAIL PROTECTED]>:
> On 10/18/07, Pavel Stehule <[EMAIL PROTECTED]> wrote:
> > this function can help with array's iteration.
> >
> > create function generate_iterator(anyarray)
> > returns setof integer
> > as $$
> > select i
> >   from generate_series(array_lower($1,1),
> >                                        array_upper($1,1)) g(i)
> > $$ language sql;
>
> There was a very similar proposal a little while back (google:
> array_to_set).  I think I like those names better since you are
> returning a set, not an iterator :-).  Also, this should be internal
> as you suggest (there is an undocumented builtin that already does
> this, _pg_expandarray).
>
> merlin
>
one sample:
create or replace function array_unpack2(anyarray)
returns setof anyelement as $$
  select $1[i][j]
     from generate_iterator($1,1) i,
              generate_iterator($1,2) j$$
language sql;

postgres=# select array_unpack2(ARRAY[[10,11,12],[13,14,15]]);
 array_unpack2
---------------
            10
            11
            12
            13
            14
            15
(6 rows)

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to [EMAIL PROTECTED] so that your
       message can get through to the mailing list cleanly

Reply via email to