On Tue, 5 Nov 2024 at 15:23, Aleksander Alekseev <aleksan...@timescale.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