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 23:20:33
Message-ID: 469954.1658100033@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 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martin Kalcher 2022-07-18 07:12:50 Re: Proposal to introduce a shuffle function to intarray extension
Previous Message Martin Kalcher 2022-07-17 23:07:22 Re: Proposal to introduce a shuffle function to intarray extension

Browse pgsql-hackers by date

  From Date Subject
Next Message Morris de Oryx 2022-07-18 01:04:21 System column support for partitioned tables using heap
Previous Message Martin Kalcher 2022-07-17 23:07:22 Re: Proposal to introduce a shuffle function to intarray extension