Re: array_random
Aleksander Alekseev <aleksander@tigerdata.com>
From: Aleksander Alekseev <aleksander@tigerdata.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Cc: jian he <jian.universality@gmail.com>,
Vik Fearing <vik@postgresfriends.org>
Date: 2025-07-08T08:45:44Z
Lists: pgsql-hackers
Hi, > it seems not trivial to wrap up all the generated random values into a specific > multi-dimensional array (more than 2 dimensions). > for example, say we generated 24 random values and wanted to arrange them into a > 3-dimensional array with shape [4, 3, 2]. > we can easily use: > SELECT array_random(1, 6, array[4,3, 2]); > > of course, we can use plpgsql to do it, but the c function would be > more convenient. > does this make sense? The proposed function seems to do two things at a time - generating random values and transforming them into an array of desired dimensions. Generally we try to avoid such interfaces. Can you think of something like array_transform() / array_reshape() that takes an arbitrary single-dimension array and modifies it?