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 1oDD2A-0003G4-K6 for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Jul 2022 22:46:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oDD29-0000rk-BL for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Jul 2022 22:46:41 +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 1oDD29-0000fu-1j for pgsql-hackers@lists.postgresql.org; Sun, 17 Jul 2022 22:46:41 +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 1oDD24-0000lq-4m for pgsql-hackers@lists.postgresql.org; Sun, 17 Jul 2022 22:46:37 +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 26HMkRHZ463182; Sun, 17 Jul 2022 18:46:27 -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: <5ef15c6f-e108-53af-3d82-587fac394f1a@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> Comments: In-reply-to Martin Kalcher message dated "Sun, 17 Jul 2022 18:15:51 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <463180.1658097987.1@sss.pgh.pa.us> Date: Sun, 17 Jul 2022 18:46:27 -0400 Message-ID: <463181.1658097987@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Martin Kalcher writes: > Am 17.07.22 um 08:00 schrieb Thomas Munro: >>> Actually ... is there a reason to bother with an intarray version >>> at all, rather than going straight for an in-core anyarray function? > I played around with the idea of an anyarray shuffle(). The hard part > was to deal with arrays with variable length elements, as they can not > be swapped easily in place. I solved it by creating an intermediate > array of references to the elements. I'll attach a patch with the proof > of concept. 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.) regards, tom lane