From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | array_random |
Date: | 2025-06-30 15:04:25 |
Message-ID: | CACJufxF8_VzCFRHRt4OHHF74QtB8tj5Z=djsy7Y31OHKG5s1-w@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
hi.
context: [1].
the attached patch already posted in [1].
I don't want to hijack another thread. so I post it in a separate thread.
The attached patch introduces a new function: array_random.
array_random description:
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).
array_random function signature:
array_random(min int4, max int4, dims int[] [, lbounds int[]]) -> int[]
array_random(min int8, max int8, dims int[] [, lbounds int[]]) -> int8[]
array_random(min numeric, max numeric, dims int[] [, lbounds int[]])
-> numeric[]
demo:
SELECT array_random(1, 6, array[2,5], array[2,4]);
array_random
--------------------------------------
[2:3][4:8]={{6,2,2,5,4},{4,5,6,4,6}}
reasons for adding array_random is:
1. This is better than array_fill. This can fill random and constant
values (random, min and max the same).
2. Building a multi-dimensional PL/pgSQL function equivalent to
array_random is not efficient and is also not easier.
Attachment | Content-Type | Size |
---|---|---|
v1-0001-array_random.patch | text/x-patch | 21.2 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Nazir Bilal Yavuz | 2025-06-30 15:15:01 | Re: [PATCH] Fix OAuth feature detection on OpenBSD+Meson |
Previous Message | Andres Freund | 2025-06-30 15:01:15 | Re: Improve error reporting in 027_stream_regress test |