Re: unnest on multi-dimensional arrays

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: unnest on multi-dimensional arrays
Дата
Msg-id 1385624101586-5780709.post@n5.nabble.com
обсуждение исходный текст
Ответ на unnest on multi-dimensional arrays  (Zev Benjamin <zev-pgsql@strangersgate.com>)
Ответы Re: unnest on multi-dimensional arrays  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Zev Benjamin wrote
> It appears that unnest, when called on a multi-dimensional array,
> effectively flattens the array first.  For example:
>
> => select * from unnest(array[array[1, 2], array[2, 3]]);
>   unnest
> --------
>        1
>        2
>        2
>        3
> (4 rows)
>
> while I would have expect something like the following:
>
> => select * from unnest(array[array[1, 2], array[2, 3]]);
>   unnest
> --------
>     {1, 2}
>     {2, 3}
> (2 rows)
>
> Is there any way to get the latter behavior?

Manually.  Cross-Join the array with a generate-series of the same length
and use the series number as an array index.  So row 1 gets cell 1 and so
forth.

Multidimensional arrays do have shortcomings in the current implementation
of which this is one.  I'm not sure, though, if there is anything
substantial and centralized in the docs so pertaining.  I may look later but
the cross-join+sequence idiom is generally useful and especially for
problems like this.

David J.





--
View this message in context:
http://postgresql.1045698.n5.nabble.com/unnest-on-multi-dimensional-arrays-tp5780706p5780709.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


В списке pgsql-general по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: unnest on multi-dimensional arrays
Следующее
От: Sergey Konoplev
Дата:
Сообщение: Re: Prefix search on all hstore values