Re: array_random - Mailing list pgsql-hackers

From jian he
Subject Re: array_random
Date
Msg-id CACJufxHUeB9L3OB7p9L1Cqnv8-nqcpi8yUPWECcds+Lk1J8EpA@mail.gmail.com
Whole thread Raw
In response to Re: array_random  (Vik Fearing <vik@postgresfriends.org>)
Responses Re: array_random
List pgsql-hackers
On Sat, Jul 5, 2025 at 3:32 PM Vik Fearing <vik@postgresfriends.org> wrote:
>
> On 30/06/2025 17:04, jian he wrote:
>
> reasons for adding array_random is:
> 1. This is better than array_fill. This can fill random and constant
> values (random, min and max the same).
> 2.  Building a multi-dimensional PL/pgSQL function equivalent to
> array_random is not efficient and is also not easier.
>
>
> I am not against this at all, but what is the actual use case?
>
> --

it seems not trivial to wrap up all the generated random values into a specific
multi-dimensional array (more than 2 dimensions).
for example, say we generated 24 random values and wanted to arrange them into a
3-dimensional array with shape [4, 3, 2].
we can easily use:
SELECT array_random(1, 6, array[4,3, 2]);

of course, we can use plpgsql to do it, but the c function would be
more convenient.
does this make sense?



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Support for 8-byte TOAST values (aka the TOAST infinite loop problem)
Next
From: Evgeny
Date:
Subject: Re: Elimination of the repetitive code at the SLRU bootstrap functions.