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 1m2jrV-0007TN-St for pgsql-general@arkaria.postgresql.org; Mon, 12 Jul 2021 00:31:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m2jrS-0002YR-OQ for pgsql-general@arkaria.postgresql.org; Mon, 12 Jul 2021 00:31:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m2jrS-0002Xj-Cb for pgsql-general@lists.postgresql.org; Mon, 12 Jul 2021 00:31:50 +0000 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m2jrN-0004lx-JI for pgsql-general@lists.postgresql.org; Mon, 12 Jul 2021 00:31:48 +0000 Received: by mail-pg1-x52e.google.com with SMTP id w15so16451717pgk.13 for ; Sun, 11 Jul 2021 17:31:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=evcEl9f7HSLFzbPGiOdW2CGIH9dj5E/yBQPNDR4dvHs=; b=QKqUVUHXfsj3H13SQArzTUDdxxkCxDuN2Mdkskaspj/twy7vggAEKTPQ8GC+ziUif3 G8bNor2DQPpTqeabmEJQKNx8FLGkeJc9kRD/fwTDSM30X1+tlOIRaVuURiGc7WA7SRpp hkNx2LV6jGB9tzmRxXvW72gU3ROrlZd/+VFfL8t/AI3kYLbyEOGpGBmTEV/Ce7PiJsul /1mzhwdAj7XGtq8Qx9Vc6WCACjkqhQv8EVEAazMdPHMiUbqiJtJE1Z1c2b5nKAtcbpLG h3aF/TogIGOYcZ7ztMxJQvrUT3SZLSY987pgNetgT0fJKSHpLxJzSI++lqc/OLQMNdMT 2Dkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=evcEl9f7HSLFzbPGiOdW2CGIH9dj5E/yBQPNDR4dvHs=; b=Cq6ImWd1Y95CpAF13JGs+mdQaCltne3mU++oulhKdjchCURxZnw7RkhUW/9NZ98yBs j1FpB+BqceVt8I0RrPWd8wHXY3QiMlrRExA4zusahTuejGQwdog54kc73jIG1TPvdStL GBuhLFzfAys3YhtRZuyWNIEod8p3ii689u7Cw2TnuHWs2z4/t6gRRSQnofjDyIkji8Zt wIjl8DbLU45VUdZTq3tXhNa9+T9QuJERAPudiKtqgiVBrEcd3XmTEMWHwWUcDvDZieJB DFcs0FkTTnXQzyZC2yWos5jZOO8JoFx7hvJas8XOkCDIurFg3jlFjIdQGD2WXWOwGEYN VF/Q== X-Gm-Message-State: AOAM532mQcw3gO67qdfJduYOotxMdXzR7uOF8avwXgwkZF+vTNqS/bGv F0YTARVCQBZWj5uj+AzPqsoeEdURNCg= X-Google-Smtp-Source: ABdhPJxNQF0Z0EnxU6quwYv859IMOEnb9pCah5ZQKxgF2Bj3FIcsd06K0pRAcg9cW4quOYLl/fJCrA== X-Received: by 2002:a63:e958:: with SMTP id q24mr50838813pgj.438.1626049903465; Sun, 11 Jul 2021 17:31:43 -0700 (PDT) Received: from smtpclient.apple ([2601:681:5500:dde0:75fd:de6d:581f:1cf5]) by smtp.gmail.com with ESMTPSA id h18sm15360381pgl.87.2021.07.11.17.31.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Jul 2021 17:31:43 -0700 (PDT) Content-Type: multipart/alternative; boundary=Apple-Mail-F6FE673B-4FC7-4E0C-9708-9FFE722DE74E Content-Transfer-Encoding: 7bit From: Rob Sargent Mime-Version: 1.0 (1.0) Subject: Re: Undocumented array_val[generate_series(...)] functionality? Date: Sun, 11 Jul 2021 18:31:42 -0600 Message-Id: <5DE6FCCC-B89D-4556-885E-D2E4F0C5A64B@gmail.com> References: Cc: "pgsql-generallists.postgresql.org" In-Reply-To: To: "David G. Johnston" X-Mailer: iPhone Mail (18F72) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail-F6FE673B-4FC7-4E0C-9708-9FFE722DE74E Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > On Jul 11, 2021, at 5:52 PM, David G. Johnston wrote: >=20 > =EF=BB=BF > Hey, >=20 > A post over in Reddit had an expression form I've never seen before: >=20 > select (array[1,2,3,4]::integer[])[generate_series(1, 3)]; > =3D=3D=3D > 1 > 2 > 3 >=20 > Looking at subscripting in the SQL syntax this example doesn't seem to be d= ocumented. >=20 > https://www.postgresql.org/docs/current/sql-expressions.html#SQL-EXPRESSIO= NS-SUBSCRIPTS >=20 > Is it documented somewhere else, and, regardless, shouldn't it be document= ed in the linked location? >=20 > I get this is basically a variant of the slice syntax [n:m], and it is wor= king as expected, but nothing indicates I can put an SRF inside the brackets= . >=20 > David J. Is that expression saying something like select the first second third eleme= nt from array 1,2,3,4? >=20 --Apple-Mail-F6FE673B-4FC7-4E0C-9708-9FFE722DE74E Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Jul 11, 2021, at 5:52 PM, David G. Johnsto= n <david.g.johnston@gmail.com> wrote:

=EF=BB=BF
Hey,
<= div class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif"= >
A post over in Reddit had an expression form I've never seen be= fore:

select (array[1,2,3,4]::integer[])[generate_series(= 1, 3)];
=3D=3D=3D
1
2
3

L= ooking at subscripting in the SQL syntax this example doesn't seem to be doc= umented.

https://www.postgresql.o= rg/docs/current/sql-expressions.html#SQL-EXPRESSIONS-SUBSCRIPTS

Is it documented somewhere else, and, regardless, should= n't it be documented in the linked location?

I get this i= s basically a variant of the slice syntax [n:m], and it is working as e= xpected, but nothing indicates I can put an SRF inside the brackets.

David J.
Is that expression s= aying something like select the first second third element from array 1,2,3,= 4?


=
= --Apple-Mail-F6FE673B-4FC7-4E0C-9708-9FFE722DE74E--