different unnest function - Mailing list pgsql-general

From Ondrej Ivanič
Subject different unnest function
Date
Msg-id CAM6mieJqHeMOpfhtC4m9U431XT758MGwPEEyjw6eT17OQXbPJQ@mail.gmail.com
Whole thread Raw
Responses Re: different unnest function
List pgsql-general
Hi,

I need function which unnest array in a different way. Input table has
ineger[][] column:
col1
----------
{{1,2,3,4}, {5,6,7,8}, {9, 10, 11, 12}}
{{11,12,13,14}, {15,16,17,18}, {19, 110, 111, 112}}
...

and output should be:

select unnest2(col1) from T
unnest2
-----------------
{1,2,3,4}
{5,6,7,8}
{9, 10, 11, 12}
{11,12,13,14}
{15,16,17,18}
{19, 110, 111, 112}

My function is:
create or replace function unnest2(anyarray) returns setof anyarray AS
$BODY$
select $1[i:i] from generate_series(array_lower($1,1), array_upper($1,1)) i;
$BODY$
language 'sql';

and the result is:
{{1,2,3,4}}
{{5,6,7,8}}
{{9, 10, 11, 12}}
{{11,12,13,14}}
{{15,16,17,18}}
{{19, 110, 111, 112}}

which is almost what I need...(or I'm at the beginning :))  Any ideas?

Thanks,
--
Ondrej Ivanic
(ondrej.ivanic@gmail.com)

pgsql-general by date:

Previous
From: Jayadevan M
Date:
Subject: Re: How to convert ByteA to Large Objects
Next
From: Craig Ringer
Date:
Subject: Re: Problem with the 9.1 one-click installer Windows7 64bit