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 1oDlCo-0004Qz-JO for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jul 2022 11:15:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oDlCn-0008Pz-EM for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jul 2022 11:15:57 +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 1oDlCn-0008P3-3s for pgsql-hackers@lists.postgresql.org; Tue, 19 Jul 2022 11:15:57 +0000 Received: from mout-b-203.mailbox.org ([2001:67c:2050:102:465::203]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oDlCg-00083j-MQ for pgsql-hackers@lists.postgresql.org; Tue, 19 Jul 2022 11:15:55 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-203.mailbox.org (Postfix) with ESMTPS id 4LnGTq6XVzz9sml; Tue, 19 Jul 2022 13:15:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aboutsource.net; s=MBO0001; t=1658229343; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5YDEcf4cPkHxxcQSp7ZZoygLj8qy29VlEYD8EA3YL5Y=; b=Qx+t0rENbCzxcDRzeI3Xsq5IUYYUegDq3mVAY0wMsHDZCU5Zk9FLJgWIBAdbeKqGnVBb9k x7lmgmRm5SwModT1sLpq7QSAmexexc0whymoHdOaIAZeRKmV2re8NTYd+sAvldvIjmMwQG ce8o77hQ6OwGftq+xmAc8EiJG4c+loi+DIMlRYqgKLFaMCtOHabOB5Q7C83ncKkw0OSWAf mtSVV/o+H7xc8blxrjC7jqZNVmrDyFCNFecr8ME3cFrBHPIaCN4kPqKcKUB3HIpJpjzxRz p2A2Fc8pwoznTLNKgpIU/BGJMPjPE/cgYYxMld92n3aoE3jgqsi6T0Kiv12cRw== Message-ID: <091a9f69-1e5d-6558-41a7-2607a5fc9ff7@aboutsource.net> Date: Tue, 19 Jul 2022 13:15:42 +0200 MIME-Version: 1.0 Content-Language: de-DE From: Martin Kalcher To: Tom Lane , Robert Haas Cc: John Naylor , Thomas Munro , PostgreSQL Hackers 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> Subject: Re: [PATCH] Introduce array_shuffle() and array_sample() In-Reply-To: <0b5dea2b-37fa-6c81-ea9d-0341ab6f87d6@aboutsource.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Am 18.07.22 um 23:48 schrieb Martin Kalcher: > > 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} > > If we go with (2) both functions should only operate on the first > dimension and shuffle whole subarrays and keep the dimensions intact. > >   select array_shuffle('{{1,2},{3,4},{5,6}}'); >   --------------------- >    {{3,4},{1,2},{5,6}} > >   select array_sample('{{1,2},{3,4},{5,6}}', 2); >   --------------- >    {{3,4},{1,2}} > Having thought about it, i would go with (2). It gives the user the ability to decide wether or not array-of-arrays behavior is desired. If he wants the behavior of (1) he can flatten the array before applying array_shuffle(). Unfortunately there is no array_flatten() function (at the moment) and the user would have to work around it with unnest() and array_agg().