Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4mzU-0004vF-Er for pgsql-docs@arkaria.postgresql.org; Wed, 27 Jan 2021 15:44:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l4mzT-0001lB-9H for pgsql-docs@arkaria.postgresql.org; Wed, 27 Jan 2021 15:44:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4mzT-0001l4-1L for pgsql-docs@lists.postgresql.org; Wed, 27 Jan 2021 15:44:19 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l4mzQ-000139-6m for pgsql-docs@lists.postgresql.org; Wed, 27 Jan 2021 15:44:18 +0000 Received: by mail-lf1-x12d.google.com with SMTP id o10so3241173lfl.13 for ; Wed, 27 Jan 2021 07:44:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:message-id:date:to; bh=4m50ua0aJeBBc+XZJmdyzTQkGjIQIVTC6loLo5BjBP8=; b=ZyJ/4YrMz6L01yHaUzYkERzH8pa8b0fz6NtTb/pCDBL5YYDYbA3x3bHBFmKAxZaIY4 EX+fgqA7DoCRMeIAja9So5t0cUwySNSc4+FiqOITWyuDPutNG6x/Mj0nJvHiSJQGuTse m3QXC9YUC01YCZuo9zC9wsvJ4ImNDXiLvmXwNeft0hN99bj3m6d5GKMLKcbbS76R5IWW /8Eo9NyA2i+tl2XhcQe9eDlAIyEvg7lreoR0eaRmVyT7ZPWIlvNlbmr+OKcrcs6bh1nJ emBezGBE2gDHnGyRVdpXKTy00bB1AAXQ5PbHe2c9YqDmb9Ay+3GyOqet62G6L3Mit00e nLHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:to; bh=4m50ua0aJeBBc+XZJmdyzTQkGjIQIVTC6loLo5BjBP8=; b=eXUi1ukvtMWkjIuju3lcutg2uo0lvwPfNuwUXRDh6SBQ1G9vHFg/gfBhU+LM9prE9k MZd/WankHcbeCl5mAffnphftzEisiHjnmo7EbAQA1AJVGTmgGwCwGU8XlTgXNFqs8nFJ 4BnqFsOXpQ14mGBbz168ywhttDGLURJq4yciNgKhfNR6ZLv758KD1wr/er8SeAV1AAG+ NntHD2e4I65StldVvrJQN40MPJAA+FwKJZQPJcsuC3rsujV2x4+f2bmsNl3eVH5i8DUk umtjuUR4pFw/lQiZTWSfNbjotXc8b3QJ/pX8JVzcA3acY/XpdA42UPTwVzr/4sPmcxV5 CTMg== X-Gm-Message-State: AOAM530NorrmucjLrqWgo4fwiPJAbs/VYR/bgaax26DAD4ZJJwGPytVd acoZNG+OzETqWlFlCtvQUGKSNTx+0xFtQw== X-Google-Smtp-Source: ABdhPJxyZTVItu48qo99LEVabRVvJQArQMnHcJ8nncqCO3+YWxrrSEoCNJ3IDuX+BKROSiGRO1X2wg== X-Received: by 2002:a19:d02:: with SMTP id 2mr4530837lfn.55.1611762253560; Wed, 27 Jan 2021 07:44:13 -0800 (PST) Received: from [192.168.88.240] ([46.39.248.116]) by smtp.gmail.com with ESMTPSA id k185sm562282lfd.239.2021.01.27.07.44.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jan 2021 07:44:13 -0800 (PST) From: - Content-Type: multipart/alternative; boundary="Apple-Mail=_909F3CFB-F367-4C91-9ECF-FFEC3B4CB81F" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.40.0.2.32\)) Subject: Better explanation of unnest with ordinality Message-Id: Date: Wed, 27 Jan 2021 18:44:11 +0300 To: pgsql-docs@lists.postgresql.org X-Mailer: Apple Mail (2.3654.40.0.2.32) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_909F3CFB-F367-4C91-9ECF-FFEC3B4CB81F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi guys! I=E2=80=99ve 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=E2=80=99ve found is here = https://www.postgresql.org/docs/13/queries-table-expressions.html = but = it=E2=80=99s not clear what is the order of function result set. = According to ISO SQL:2011 standard draft (the only one I=E2=80=99ve = found in internet) (7.6 ) 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=E2=80=99s an intentional deviation from standard = so we can=E2=80=99t rely on =3D=3D ? --Apple-Mail=_909F3CFB-F367-4C91-9ECF-FFEC3B4CB81F Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hi guys!
I=E2=80=99= 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=E2=80=99ve found is here https://www.postgresql.org/docs/13/queries-table-expressions.ht= ml but it=E2=80=99s not clear what is the order of function = result set. According to ISO SQL:2011 standard draft (the only one = I=E2=80=99ve 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=E2=80=99s an = intentional deviation from standard so we can=E2=80=99t rely on = <ordinality> =3D=3D <element index in array>?
= --Apple-Mail=_909F3CFB-F367-4C91-9ECF-FFEC3B4CB81F--