Better explanation of unnest with ordinality
Better explanation of unnest with ordinality
От:
- <m7onov@gmail.com>
Дата:
Hi guys!
I’ve recently come across a query of the kind:
select * from unnest(array[1,2,3,4]) with ordinality t;
I’ve recently come across a query of the kind:
select * from unnest(array[1,2,3,4]) with ordinality t;
and was asked whether ordinality value is guaranteed to be the same as the array index of the array element in the same tuple. The only relevant thing about ordinality column I’ve found is here https://www.postgresql.org/docs/13/queries-table-expressions.html but it’s not clear what is the order of function result set. According to ISO SQL:2011 standard draft (the only one I’ve found in internet) (7.6 <table reference>) unnest is not a function but a special syntax to make a table from collection. It states that in case of array argument and "with ordinality" this statement returns ordinality column that matches array indexes. Is it possible to clear it out in docs or maybe it’s an intentional deviation from standard so we can’t rely on <ordinality> == <element index in array>?
Re: Better explanation of unnest with ordinality
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
- writes: > I’ve recently come across a query of the kind: > select * from unnest(array[1,2,3,4]) with ordinality t; > and was asked whether ordinality value is guaranteed to be the same as the array index of the array element in the same tuple. The only relevant thing about ordinality column I’ve found is here https://www.postgresql.org/docs/13/queries-table-expressions.html but it’s not clear what is the order of function result set. According to ISO SQL:2011 standard draft (the only one I’ve found in internet) (7.6
Re: Better explanation of unnest with ordinality
От:
"m7onov@gmail.com" <m7onov@gmail.com>
Дата:
On Wed, Jan 27, 2021 at 7:47 PM Tom Lane wrote: > > What is less clear is the definition of UNNEST, for which that text refers > you to 9.19 What about some json functions that return setof, e.g. jsonb_to_recordset (https://www.postgresql.org/docs/13/functions-json.html)? Should we keep the same semantics with json array ordering as with ordinary arrays?