Re: Proposal to introduce a shuffle function to intarray extension

Martin Kalcher <martin.kalcher@aboutsource.net>

From: Martin Kalcher <martin.kalcher@aboutsource.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Thomas Munro <thomas.munro@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-07-17T23:05:19Z
Lists: pgsql-hackers, pgsql-general
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.)
> 
> 			regards, tom lane

deconstruct_array() would destroy the arrays dimensions. I would expect 
that shuffle() only shuffles the first dimension and keeps the inner 
arrays intact.

Martin



Commits

  1. Add array_sample() and array_shuffle() functions.

  2. Use a separate random seed for SQL random()/setseed() functions.