Re: Proposal to introduce a shuffle function to intarray extension - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Proposal to introduce a shuffle function to intarray extension
Date
Msg-id 463181.1658097987@sss.pgh.pa.us
Whole thread Raw
In response to Re: Proposal to introduce a shuffle function to intarray extension  (Martin Kalcher <martin.kalcher@aboutsource.net>)
Responses Re: Proposal to introduce a shuffle function to intarray extension
List pgsql-hackers
Martin Kalcher <martin.kalcher@aboutsource.net> 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



pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Re: Proposal to introduce a shuffle function to intarray extension
Next
From: Tom Lane
Date:
Subject: Re: Proposal to introduce a shuffle function to intarray extension