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 1pjS1E-0007po-T4 for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Apr 2023 21:47:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pjS1D-0006X1-EN for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Apr 2023 21:47:15 +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 1pjS1D-0006Ws-54 for pgsql-hackers@lists.postgresql.org; Mon, 03 Apr 2023 21:47:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pjS1A-0008TP-R9 for pgsql-hackers@lists.postgresql.org; Mon, 03 Apr 2023 21:47:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 333Lkvcx1275445; Mon, 3 Apr 2023 17:46:57 -0400 From: Tom Lane To: Daniel Gustafsson cc: Martin Kalcher , Fabien COELHO , Andres Freund , Dean Rasheed , Robert Haas , Andrew Dunstan , John Naylor , Thomas Munro , PostgreSQL Hackers Subject: Re: [PATCH] Introduce array_shuffle() and array_sample() In-reply-to: <110FCCA3-8159-4A06-9876-815D8E5218C9@yesql.se> References: <459f6008-90bc-bc52-6f11-e68570e03ac0@aboutsource.net> <583b6409-df52-86d1-8c0a-ce8e74863ad7@aboutsource.net> <036ba529-1f25-d7b5-c5ad-e6c852d928df@aboutsource.net> <8fabf9e7-3422-58b0-93f6-d0976d4679df@aboutsource.net> <20220922152320.ukx6teo7wa7cuwkv@awork3.anarazel.de> <193caac5-941e-58b8-65e6-351f777ebd25@aboutsource.net> <3502301.1664223385@sss.pgh.pa.us> <9cd0925c-9839-a136-c21d-87de9e8a3aa4@aboutsource.net> <3943591.1664374725@sss.pgh.pa.us> <344667.1664480006@sss.pgh.pa.us> <110FCCA3-8159-4A06-9876-815! D8E5218C9@yesql.se> Comments: In-reply-to Daniel Gustafsson message dated "Mon, 03 Apr 2023 23:25:39 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1275443.1680558417.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 03 Apr 2023 17:46:57 -0400 Message-ID: <1275444.1680558417@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Daniel Gustafsson writes: > On 29 Sep 2022, at 21:33, Tom Lane wrote: >> I find this behavior a bit surprising: >> = >> +SELECT array_dims(array_sample('[-1:2][2:3]=3D{{1,2},{3,NULL},{5,6},{7= ,8}}'::int[], 3)); >> + array_dims = >> +------------- >> + [-1:1][2:3] >> +(1 row) >> = >> I can buy preserving the lower bound in array_shuffle(), but >> array_sample() is not preserving the first-dimension indexes of >> the array, so ISTM it ought to reset the first lower bound to 1. > I might be daft but I'm not sure I follow why not preserving here, can y= ou > explain? Because array_sample selects only some of the (first level) array elements, those elements are typically not going to have the same indexes in the output as they did in the input. So I don't see why it would be useful to preserve the same lower-bound index. It does make sense to preserve the lower-order index bounds ([2:3] in this example) because we are including or not including those array slices as a whole. regards, tom lane