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 1oDYc2-0008UR-Jt for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Jul 2022 21:49:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oDYc0-00047v-Ev for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Jul 2022 21:49:08 +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 1oDYc0-00047m-4I for pgsql-hackers@lists.postgresql.org; Mon, 18 Jul 2022 21:49:08 +0000 Received: from mout-b-110.mailbox.org ([195.10.208.55]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oDYbw-0001Lf-Sd for pgsql-hackers@lists.postgresql.org; Mon, 18 Jul 2022 21:49:06 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (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-110.mailbox.org (Postfix) with ESMTPS id 4LmwZx3T3Nz9sZr; Mon, 18 Jul 2022 23:48:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aboutsource.net; s=MBO0001; t=1658180937; 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=qdcoOik18D3TJcVYFNFHeKBmRSrLw+2Pzz5xj0T9HMg=; b=NtggwDezcRt5rZAfMO7NOWx6IXkYU7qp5MyXsbCqcUdJMk7Pd5JxQqXcbrDIQa5ZTlEth8 /LTTUX4mZvPa7R42A+CBurZhK26BEpwneVq5mryC5E8OL+AkEHXhyFbCZnLjgMWL3LGv6e 07Mo34ELawpQJEtUAp4urfqcUWM8lEfwT8vMZoVGQzoz/hygIIBNOuQgrGg8ZSAGaQpqb/ e8U3j5Up0qTmIvGqXh2gKMIWeQbEW2WnWNW112hw250nLq5l2DeafV3E4xff4Et2CM5OJF HxkTDkjMrEeyGuxXTNzs+xh5kA3Z8l784TRK+6/wjazth4qnp5wqF83LGCSabQ== Message-ID: <0b5dea2b-37fa-6c81-ea9d-0341ab6f87d6@aboutsource.net> Date: Mon, 18 Jul 2022 23:48:55 +0200 MIME-Version: 1.0 Content-Language: de-DE 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> From: Martin Kalcher Subject: Re: [PATCH] Introduce array_shuffle() and array_sample() In-Reply-To: <817328.1658178181@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Am 18.07.22 um 23:03 schrieb Tom Lane: > I wrote: >> Martin had originally proposed (2), which I rejected on the grounds >> that we don't treat multi-dimensional arrays as arrays-of-arrays for >> any other purpose. > > Actually, after poking at it for awhile, that's an overstatement. > It's true that the type system doesn't think N-D arrays are > arrays-of-arrays, but there are individual functions/operators that do. > Thanks Robert for pointing out the inconsistent behavior of array_sample(). That needs to be fixed. As Tom's investigation showed, there is no consensus in the code if multi-dimensional arrays are treated as arrays-of-arrays or not. We need to decide what should be the correct treatment. 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}} I do not feel qualified to make that decision. (2) complicates the code a bit, but that should not be the main argument here. Martin