I understand that using
SELECT unnest(ARRAY[5,3,9]) as id
without an ORDER BY
clause, the order of the result set is not guaranteed. I could for example get:
id
--
3
5
9
But what about the following request:
SELECT
unnest(ARRAY[5,3,9]) as id,
unnest(ARRAY(select generate_series(1, array_length(ARRAY[5,3,9], 1)))) as idx
ORDER BY idx ASC
Is it guaranteed that the 2 unnest()
calls (which have the same length) will unroll in parallel and that the index idx
will indeed match the position of the item in the array?
I am using PostgreSQL 9.3.3.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…