Re: [PATCH] Introduce array_shuffle() and array_sample()
David G. Johnston <david.g.johnston@gmail.com>
From: "David G. Johnston" <david.g.johnston@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Martin Kalcher <martin.kalcher@aboutsource.net>,
Robert Haas <robertmhaas@gmail.com>, John Naylor <john.naylor@enterprisedb.com>,
Thomas Munro <thomas.munro@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-07-18T22:32:00Z
Lists: pgsql-hackers, pgsql-general
On Mon, Jul 18, 2022 at 3:18 PM Tom Lane <tgl@sss.pgh.pa.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.
Commits
-
Add array_sample() and array_shuffle() functions.
- 888f2ea0a81f 16.0 landed
-
Use a separate random seed for SQL random()/setseed() functions.
- 6645ad6bdd81 12.0 cited