Re: Proposal to introduce a shuffle function to intarray extension

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Martin Kalcher <martin(dot)kalcher(at)aboutsource(dot)net>
Cc: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Proposal to introduce a shuffle function to intarray extension
Date: 2022-07-17 22:46:27
Message-ID: 463181.1658097987@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Martin Kalcher <martin(dot)kalcher(at)aboutsource(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2022-07-17 22:53:31 Re: Proposal to introduce a shuffle function to intarray extension
Previous Message Thomas Munro 2022-07-17 22:37:04 Re: Proposal to introduce a shuffle function to intarray extension

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-07-17 22:53:31 Re: Proposal to introduce a shuffle function to intarray extension
Previous Message Thomas Munro 2022-07-17 22:37:04 Re: Proposal to introduce a shuffle function to intarray extension