Re: New function normal_rand_array function to contrib/tablefunc. - Mailing list pgsql-hackers

From Aleksander Alekseev
Subject Re: New function normal_rand_array function to contrib/tablefunc.
Date
Msg-id CAJ7c6TO8N4hE7zFKrf90uyS1ct+UCEzYuzq6=pG=e4eZykwRgQ@mail.gmail.com
Whole thread Raw
In response to Re: New function normal_rand_array function to contrib/tablefunc.  (Aleksander Alekseev <aleksander@timescale.com>)
Responses Re: New function normal_rand_array function to contrib/tablefunc.
List pgsql-hackers
Hi,

> I played with patch v3. All in all it seems to be in good shape.
>
> I wonder though whether tablefunc extension is the right place for the
> function. To me it seems to be as useful as array_shuffle().
>
> Personally I would name the function array_rand() in order to be
> consistent with the rest of array_* functions [1].
>
> I would also replace `minlen` and `maxlen` arguments with a single
> `len` argument because the same result (although more slowly) can be
> achieved like this:
>
> SELECT trim_array(arr, random(0,3)) FROM rand_array(10, 3, 3, 50::int,
> 80::int) as arr;
>
> This could be just a bike-shedding though. Does anyone feel necessary
> to second any of these nitpicks?
>
> [1]: https://www.postgresql.org/docs/current/functions-array.html

On second thought, is there really much value in returning a setof?
Any reason not to have an interface as simple and straightforward as
this:

```
=# SELECT array_random(1, 10, random(0, 3)) FROM generate_series( ... )
{5}
{1, 3, 8}
{7, 6}
...
```

? Or maybe I'm missing something?

-- 
Best regards,
Aleksander Alekseev



pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: pg_dump --no-comments confusion
Next
From: vignesh C
Date:
Subject: Re: Pgoutput not capturing the generated columns