Re: [PATCH] Introduce array_shuffle() and array_sample()

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Martin Kalcher <martin(dot)kalcher(at)aboutsource(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, John Naylor <john(dot)naylor(at)enterprisedb(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Introduce array_shuffle() and array_sample()
Date: 2022-07-18 22:32:00
Message-ID: CAKFQuwZ9o3Nw5TVgPf9xeTc73ad=BYJjT9werq6ztp6Lb_FVHA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Mon, Jul 18, 2022 at 3:18 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

>
> Independently of the dimensionality question --- I'd imagined that
> array_sample would select a random subset of the array elements
> but keep their order intact. If you want the behavior shown
> above, you can do array_shuffle(array_sample(...)). But if we
> randomize it, and that's not what the user wanted, she has no
> recourse.
>
>
And for those that want to know in what order those elements were chosen
they have no recourse in the other setup.

I really think this function needs to grow an algorithm argument that can
be used to specify stuff like ordering, replacement/without-replacement,
etc...just some enums separated by commas that can be added to the call.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2022-07-18 22:43:32 Re: [PATCH] Introduce array_shuffle() and array_sample()
Previous Message Tom Lane 2022-07-18 22:18:40 Re: [PATCH] Introduce array_shuffle() and array_sample()

Browse pgsql-hackers by date

  From Date Subject
Next Message Justin Pryzby 2022-07-18 22:32:40 Re: Commitfest Update
Previous Message Tom Lane 2022-07-18 22:18:40 Re: [PATCH] Introduce array_shuffle() and array_sample()