How to unnest an array with element indexes

Поиск
Список
Период
Сортировка
От AlexK
Тема How to unnest an array with element indexes
Дата
Msg-id 1392837956043-5792770.post@n5.nabble.com
обсуждение исходный текст
Ответы Re: How to unnest an array with element indexes  (David Johnston <polobo@yahoo.com>)
Список pgsql-sql
Given an array such as ARRAY[1.1,1.2], I need to select both values and
indexes, as follows:

1;1.1
2;1.2

The following query does what I want for a simple example:

with pivoted_array AS(
select unnest(ARRAY[1.1,1.2])
)
select ROW_NUMBER() OVER() AS element_index, unnest as element_value
from pivoted_array

Is ROW_NUMBER() OVER() guaranteed to always return array's index? If not,
how should I predictably/deterministically do it?



--
View this message in context:
http://postgresql.1045698.n5.nabble.com/How-to-unnest-an-array-with-element-indexes-tp5792770.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.



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

Предыдущее
От: David Johnston
Дата:
Сообщение: Re: include ids in query grouped by multipe values
Следующее
От: David Johnston
Дата:
Сообщение: Re: How to unnest an array with element indexes