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 1oDDa8-000550-Ky for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Jul 2022 23:21:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oDDZ9-0007b3-9B for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Jul 2022 23:20:47 +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 1oDDZ8-0007au-WA for pgsql-hackers@lists.postgresql.org; Sun, 17 Jul 2022 23:20:47 +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 1oDDZ2-00011l-K1 for pgsql-hackers@lists.postgresql.org; Sun, 17 Jul 2022 23:20:45 +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 26HNKX5r469955; Sun, 17 Jul 2022 19:20:33 -0400 From: Tom Lane To: Martin Kalcher cc: Thomas Munro , PostgreSQL Hackers Subject: Re: Proposal to introduce a shuffle function to intarray extension In-reply-to: <5b7a1ee9-f942-2502-3a0c-e9fc12511139@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> Comments: In-reply-to Martin Kalcher message dated "Mon, 18 Jul 2022 01:05:19 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <469953.1658100033.1@sss.pgh.pa.us> Date: Sun, 17 Jul 2022 19:20:33 -0400 Message-ID: <469954.1658100033@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Martin Kalcher writes: > Am 18.07.22 um 00:46 schrieb Tom Lane: >> This does not look particularly idiomatic, or even type-safe. What you >> should have done was use deconstruct_array to get an array of Datums and >> isnull flags, then shuffled those, then used construct_array to build the >> output. >> >> (Or, perhaps, use construct_md_array to replicate the input's >> precise dimensionality. Not sure if anyone would care.) > deconstruct_array() would destroy the arrays dimensions. As I said, you can use construct_md_array if you want to preserve the array shape. > I would expect that shuffle() only shuffles the first dimension and > keeps the inner arrays intact. This argument is based on a false premise, ie that Postgres thinks multidimensional arrays are arrays-of-arrays. They aren't, and we're not going to start making them so by defining shuffle() at variance with every other array-manipulating function. Shuffling the individual elements regardless of array shape is the definition that's consistent with our existing functionality. (Having said that, even if we were going to implement it with that definition, I should think that it'd be easiest to do so on the array-of-Datums representation produced by deconstruct_array. That way you don't need to do different things for different element types.) regards, tom lane