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

From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: Martin Kalcher <martin(dot)kalcher(at)aboutsource(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, 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-19 10:07:29
Message-ID: CAJ7c6TNeJYLVAGSEHYizaR+j=7UOHHrG=supAk-gU_a9Hx76_A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Hi Martin,

I didn't look at the code yet but I very much like the idea. Many
thanks for working on this!

It's a pity your patch was too late for the July commitfest. In
September, please keep an eye on cfbot [1] to make sure your patch
applies properly.

> As Tom's investigation showed, there is no consensus in the code if
> multi-dimensional arrays are treated as arrays-of-arrays or not. We need
> to decide what should be the correct treatment.

Here are my two cents.

From the user perspective I would expect that by default a
multidimensional array should be treated as an array of arrays. So for
instance:

```
array_shuffle([ [1,2], [3,4], [5,6] ])
```

... should return something like:

```
[ [3,4], [1,2], [5,6] ]
```

Note that the order of the elements in the internal arrays is preserved.

However, I believe there should be an optional argument that overrides
this behavior. For instance:

```
array_shuffle([ [1,2], [3,4], [5,6] ], depth => 2)
```

BTW, while on it, shouldn't we add similar functions for JSON and/or
JSONB? Or is this going to be too much for a single discussion?

[1]: http://cfbot.cputube.org/

--
Best regards,
Aleksander Alekseev

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Abdul Qoyyuum 2022-07-19 10:10:13 Re: pg_dump is filling C: drive up to 100 percent
Previous Message Abdul Qoyyuum 2022-07-19 10:07:14 Re: Setting up a server with previous day data

Browse pgsql-hackers by date

  From Date Subject
Next Message Japin Li 2022-07-19 10:41:13 Re: Memory leak fix in psql
Previous Message Andrey Lepikhov 2022-07-19 09:35:22 Re: Fast COPY FROM based on batch insert