Skip to content

Instantly share code, notes, and snippets.

View AlexisWilke's full-sized avatar

Alexis Wilke AlexisWilke

View GitHub Profile
@ekho
ekho / pg_random_int_array.sql
Last active February 9, 2024 13:47
Postgresql function for generating random integer array
CREATE OR REPLACE FUNCTION random_int_array(dim integer, min integer, max integer) RETURNS integer[] AS $BODY$
begin
return (select array_agg(round(random() * (max - min)) + min) from generate_series (0, dim));
end
$BODY$ LANGUAGE plpgsql;
-- usage example
select random_int_array(15, 6, 40);
-- return example