Files
development/4dev/database/function/random_string.sql
2022-12-06 09:27:08 +09:00

21 lines
450 B
PL/PgSQL

-- create random string with length X
CREATE FUNCTION random_string(randomLength int)
RETURNS text AS
$$
SELECT array_to_string(
ARRAY(
SELECT substring(
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
trunc(random() * 62)::int + 1,
1
)
FROM generate_series(1, randomLength) AS gs(x)
),
''
)
$$
LANGUAGE SQL
RETURNS NULL ON NULL INPUT
VOLATILE; -- LEAKPROOF;