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 1oDZ4m-0001TX-GZ for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Jul 2022 22:18:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oDZ4l-00070v-DZ for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Jul 2022 22:18:51 +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 1oDZ4l-00070d-4k for pgsql-hackers@lists.postgresql.org; Mon, 18 Jul 2022 22:18:51 +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 1oDZ4j-0004T8-0T for pgsql-hackers@lists.postgresql.org; Mon, 18 Jul 2022 22:18:50 +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 26IMIeTV840272; Mon, 18 Jul 2022 18:18:40 -0400 From: Tom Lane To: Martin Kalcher cc: Robert Haas , John Naylor , Thomas Munro , PostgreSQL Hackers Subject: Re: [PATCH] Introduce array_shuffle() and array_sample() In-reply-to: <0b5dea2b-37fa-6c81-ea9d-0341ab6f87d6@aboutsource.net> References: <9d160a44-7675-51e8-60cf-6d64b76db831@aboutsource.net> <4073858.1658027909@sss.pgh.pa.us> <4077925.1658029046@sss.pgh.pa.us> <5ef15c6f-e108-53af-3d82-587fac394f1a@aboutsource.net> <463181.1658097987@sss.pgh.pa.us> <5b7a1ee9-f942-2502-3a0c-e9fc12511139@aboutsource.net> <469954.1658100033@sss.pgh.pa.us> <687490.1658152096@sss.pgh.pa.us> <1708d95a-629e-5ac5-deab-d20a8d0b2b0e@aboutsource.net> <809171.1658176490@sss.pgh.pa.us> <817328.1658178181@sss.pgh.pa.us> <0b5dea2b-37fa-6c81-ea9d-0341ab6f87d6@aboutsource.net> Comments: In-reply-to Martin Kalcher message dated "Mon, 18 Jul 2022 23:48:55 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <840270.1658182720.1@sss.pgh.pa.us> Date: Mon, 18 Jul 2022 18:18:40 -0400 Message-ID: <840271.1658182720@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Martin Kalcher writes: > If we go with (1) array_shuffle() and array_sample() should shuffle each > element individually and always return a one-dimensional array. > select array_shuffle('{{1,2},{3,4},{5,6}}'); > ----------- > {1,4,3,5,6,2} > select array_sample('{{1,2},{3,4},{5,6}}', 3); > ---------- > {1,4,3} Independently of the dimensionality question --- I'd imagined that array_sample would select a random subset of the array elements but keep their order intact. If you want the behavior shown above, you can do array_shuffle(array_sample(...)). But if we randomize it, and that's not what the user wanted, she has no recourse. Now, if you're convinced that the set of people wanting sampling-without-shuffling is the empty set, then making everybody else call two functions is a loser. But I'm not convinced. At the least, I'd like to see the argument made why nobody would want that. regards, tom lane