Re: New function normal_rand_array function to contrib/tablefunc.

2024-11-06 Thread Andy Fan
Hi, Looks I miss some interesting dicussions in the recent days, the pretty neat API random_array, random_array or array_random (I prefer the random_array because of the setseed stuff as Dean said). These dicussions absoluatly enrichs my API / decoument design experience. I'm still not sure if

Re: New function normal_rand_array function to contrib/tablefunc.

2024-11-05 Thread Aleksander Alekseev
Hi, > 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

Re: New function normal_rand_array function to contrib/tablefunc.

2024-11-05 Thread Dean Rasheed
On Tue, 5 Nov 2024 at 15:23, Aleksander Alekseev 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 tr

Re: New function normal_rand_array function to contrib/tablefunc.

2024-11-05 Thread Aleksander Alekseev
Hi Dean, Thanks for your input. > > 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} > > ... > > > > Yeah, that looks like a neater API. > > Something tha

Re: New function normal_rand_array function to contrib/tablefunc.

2024-11-04 Thread Dean Rasheed
On Mon, 4 Nov 2024 at 14:46, Aleksander Alekseev wrote: > > 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} > ... > Yeah, that looks like a neater API. Something th

Re: New function normal_rand_array function to contrib/tablefunc.

2024-11-04 Thread Aleksander Alekseev
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 th

Re: New function normal_rand_array function to contrib/tablefunc.

2024-11-04 Thread Aleksander Alekseev
Hi everyone, > >> Thanks for the detailed feedback! Here is the rebased version. > >> > > > > I took another look at this and I think it's in reasonable shape. > > > > I'm attaching an update, rebasing it on top of 9be4e5d293. > > Thank you Dean. > > > Also it was missing a required update to the

Re: New function normal_rand_array function to contrib/tablefunc.

2024-11-03 Thread Andy Fan
Dean Rasheed writes: > On Wed, 16 Oct 2024 at 08:43, Andy Fan wrote: >> >> Thanks for the detailed feedback! Here is the rebased version. >> > > I took another look at this and I think it's in reasonable shape. > > I'm attaching an update, rebasing it on top of 9be4e5d293. Thank you Dean. >

Re: New function normal_rand_array function to contrib/tablefunc.

2024-11-01 Thread Japin Li
On Fri, 01 Nov 2024 at 09:33, Dean Rasheed wrote: > On Wed, 16 Oct 2024 at 08:43, Andy Fan wrote: >> >> Thanks for the detailed feedback! Here is the rebased version. >> > > I took another look at this and I think it's in reasonable shape. > > I'm attaching an update, rebasing it on top of 9be4e

Re: New function normal_rand_array function to contrib/tablefunc.

2024-11-01 Thread Dean Rasheed
On Wed, 16 Oct 2024 at 08:43, Andy Fan wrote: > > Thanks for the detailed feedback! Here is the rebased version. > I took another look at this and I think it's in reasonable shape. I'm attaching an update, rebasing it on top of 9be4e5d293. Also it was missing a required update to the meson.bui

Re: New function normal_rand_array function to contrib/tablefunc.

2024-10-26 Thread Andy Fan
Dean Rasheed writes: > On Sat, 26 Oct 2024 at 01:51, Andy Fan wrote: >> >> > 10). In this error: >> > >> > +elog(ERROR, "unsupported type %d for rand_array function.", >> > + datatype); >> > >> > "datatype" is of type Oid, which is unsigned, and so it should use >> > "%u" not

Re: New function normal_rand_array function to contrib/tablefunc.

2024-10-26 Thread Dean Rasheed
On Sat, 26 Oct 2024 at 01:51, Andy Fan wrote: > > > 10). In this error: > > > > +elog(ERROR, "unsupported type %d for rand_array function.", > > + datatype); > > > > "datatype" is of type Oid, which is unsigned, and so it should use > > "%u" not "%d". Also, as above, it should

Re: New function normal_rand_array function to contrib/tablefunc.

2024-10-25 Thread Andy Fan
> 10). In this error: > > +elog(ERROR, "unsupported type %d for rand_array function.", > + datatype); > > "datatype" is of type Oid, which is unsigned, and so it should use > "%u" not "%d". Also, as above, it should not end with a period, so it > should be: > > +elog(E

Re: New function normal_rand_array function to contrib/tablefunc.

2024-10-16 Thread Andy Fan
Hello Dean, Thanks for the detailed feedback! Here is the rebased version. > 1). In the tests: > > +select setseed(0.8); > +select rand_array(10, 0, 3, 50::int, 80::int); .. > this should really have a comment block to distinguish these new tests > from the preceeding normal_rand() tests. > 3

Re: New function normal_rand_array function to contrib/tablefunc.

2024-10-15 Thread Dean Rasheed
On Thu, 29 Aug 2024 at 05:39, Andy Fan wrote: > > Yes, that's a valid usage. the new vesion is attached. I have changed > the the commit entry [1] from "Waiting on Author" to "Needs review". > Note that this needs a rebase, following commit 4681ad4b2f. Here are a few more review comments: 1).

Re: New function normal_rand_array function to contrib/tablefunc.

2024-08-28 Thread Andy Fan
Japin Li writes: > On Wed, 28 Aug 2024 at 12:27, Andy Fan wrote: >> Japin Li writes: >> > Nitpick, the minlen is smaller than maxlen, so the maxlen cannot be zero. > > After giving it some more thought, it would also be helpful if maxlen is > equal to minlen. > > For example, I want have each r

Re: New function normal_rand_array function to contrib/tablefunc.

2024-08-27 Thread Japin Li
On Wed, 28 Aug 2024 at 12:27, Andy Fan wrote: > Japin Li writes: > > >> Thanks for updating the patch. Here are some comments. >> >> +if (minlen >= maxlen) >> +ereport(ERROR, >> +(errcode(ERRCODE_INVALID_PARAMETER_VALUE), >> +

Re: New function normal_rand_array function to contrib/tablefunc.

2024-08-27 Thread Andy Fan
Japin Li writes: > Thanks for updating the patch. Here are some comments. > > + if (minlen >= maxlen) > + ereport(ERROR, > + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), > + errmsg("minlen must be greater than > maxlen.")));

Re: New function normal_rand_array function to contrib/tablefunc.

2024-08-27 Thread Japin Li
On Tue, 27 Aug 2024 at 16:43, Andy Fan wrote: > Andy Fan writes: > My suggestion would be to mirror the signatures of the core random() functions more closely, and have this: 1). rand_array(numvals int, minlen int, maxlen int) returns setof float8[] >> ..> 4

Re: New function normal_rand_array function to contrib/tablefunc.

2024-08-27 Thread Andy Fan
Andy Fan writes: >>> My suggestion would be to mirror the signatures of the core random() >>> functions more closely, and have this: >>> >>> 1). rand_array(numvals int, minlen int, maxlen int) >>> returns setof float8[] >>> > ..> >>> 4). rand_array(numvals int, minlen int, maxlen int, >>>

Re: New function normal_rand_array function to contrib/tablefunc.

2024-08-26 Thread Andy Fan
Dean Rasheed writes: Hello Dean, >> I did have some issue to run 'make html', but the >> error exists before my patch, so I change the document carefully without >> testing it. do you know how to fix the below error in 'make html'? >> >> $/usr/bin/xsltproc --nonet --path . --path . --stringpara

Re: New function normal_rand_array function to contrib/tablefunc.

2024-07-17 Thread Dean Rasheed
On Wed, 17 Jul 2024 at 07:29, Andy Fan wrote: > > It is just not clear to me how verbose the document should to be, and > where the document should be, tablefunc.sgml, the comment above the > function or the places just the code? In many cases you provides above > or below are just implementation

Re: New function normal_rand_array function to contrib/tablefunc.

2024-07-16 Thread Andy Fan
Andy Fan writes: (just noticed this reply is sent to Jim privately, re-sent it to public.) > Hi Jim, > >> >> When either minval or maxval exceeds int4 the function cannot be >> executed/found >> >> SELECT * FROM normal_rand_array(5, 10, 8, 42::bigint); >> >> ERROR:  function normal_rand_array(i

Re: New function normal_rand_array function to contrib/tablefunc.

2024-07-16 Thread Andy Fan
Dean Rasheed writes: > My suggestion would be to mirror the signatures of the core random() > functions more closely, and have this: > > 1). rand_array(numvals int, minlen int, maxlen int) > returns setof float8[] > > 2). rand_array(numvals int, minlen int, maxlen int, >minval

Re: New function normal_rand_array function to contrib/tablefunc.

2024-07-15 Thread Dean Rasheed
On Tue, 2 Jul 2024 at 11:18, Jim Jones wrote: > > When either minval or maxval exceeds int4 the function cannot be > executed/found > > SELECT * FROM normal_rand_array(5, 10, 8, 42::bigint); > > ERROR: function normal_rand_array(integer, integer, integer, bigint) > does not exist > LINE 1: SELECT

Re: New function normal_rand_array function to contrib/tablefunc.

2024-07-02 Thread Jim Jones
Hi Andy On 08.06.24 08:05, Andy Fan wrote: > Here is a new function which could produce an array of numbers with a > controllable array length and duplicated elements in these arrays. I > used it when working with gin index, and I think it would be helpful for > others as well, so here it is. > >

Re: New function normal_rand_array function to contrib/tablefunc.

2024-06-24 Thread Stepan Neretin
It looks useful, for example, it can be used in sorting tests to make them more interesting. I just have one question. Why are you using SRF_IS_FIRST CALL and not _PG_init? Best regards, Stepan Neretin.

New function normal_rand_array function to contrib/tablefunc.

2024-06-07 Thread Andy Fan
Here is a new function which could produce an array of numbers with a controllable array length and duplicated elements in these arrays. I used it when working with gin index, and I think it would be helpful for others as well, so here it is. select * from normal_rand_array(5, 10, 1.8::numeric, 3