From: - <m7onov@gmail.com>
To: pgsql-docs@lists.postgresql.org
Subject: Better explanation of unnest with ordinality
Date: Wed, 27 Jan 2021 18:44:11 +0300
Message-ID: <FF1FB31F-0507-4F18-9559-2DE6E07E3B43@gmail.com> (raw)
Hi guys!
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 <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>?
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-docs@postgresql.org
Cc: m7onov@gmail.com, pgsql-docs@lists.postgresql.org
Subject: Re: Better explanation of unnest with ordinality
In-Reply-To: <FF1FB31F-0507-4F18-9559-2DE6E07E3B43@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox