Re: New function normal_rand_array function to contrib/tablefunc.

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andy Fan <zhihuifan1213(at)163(dot)com>, Japin Li <japinli(at)hotmail(dot)com>, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Subject: Re: New function normal_rand_array function to contrib/tablefunc.
Date: 2024-11-05 16:19:48
Message-ID: CAEZATCWCOCQQe2vDt2T0whFP09RR=OSrvqYE2Y631mcL98m1eg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 5 Nov 2024 at 15:23, Aleksander Alekseev
<aleksander(at)timescale(dot)com> wrote:
>
> > > =# SELECT array_random(1, 10, random(0, 3)) FROM generate_series( ... )
> > > {5}
> > > {1, 3, 8}
> > > {7, 6}
> > > ...
> >
> > Yeah, that looks like a neater API.
> >
> > Something that bothers me somewhat is that it's completely trivial for
> > the user to write such a function for themselves, so is it really
> > useful enough to include in core?
>
> I think it would be useful. Many users don't bother writing C
> extensions for tasks like this. So at least our implementation is
> going to be faster.
>

If we are going to add such a function to core, then I think we should
make it consistent and at least as flexible as the other array
functions, and support multi-dimensional arrays with optional
non-default lower-bounds, like array_fill(). I.e., something like:

random_array(min int, max int, dims int[] [, lbounds int[]]) -> int[]

Returns an array filled with random values in the range min <= x <= max,
having dimensions of the lengths specified by dims. The optional lbounds
argument supplies lower-bound values for each dimension (which default
to all 1).

Regards,
Dean

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2024-11-05 16:21:42 Re: Virtual generated columns
Previous Message Peter Eisentraut 2024-11-05 16:19:01 Re: Virtual generated columns