different unnest function

Поиск
Список
Период
Сортировка
От Ondrej Ivanič
Тема different unnest function
Дата
Msg-id CAM6mieJqHeMOpfhtC4m9U431XT758MGwPEEyjw6eT17OQXbPJQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: different unnest function
Список 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 по дате отправления:

Предыдущее
От: Jayadevan M
Дата:
Сообщение: Re: How to convert ByteA to Large Objects
Следующее
От: Craig Ringer
Дата:
Сообщение: Re: Problem with the 9.1 one-click installer Windows7 64bit