Postgres 生成任意长度随机字符串

2017-06-27  本文已影响0人  AngryApe

create function f_random_str(length INTEGER) returns character varying
LANGUAGE plpgsql
AS $$
DECLARE
result varchar(50);
BEGIN
SELECT array_to_string(ARRAY(SELECT chr((65 + round(random() * 25)) :: integer)
FROM generate_series(1,length)), '') INTO result;
return result;
END
$$;

上一篇 下一篇

猜你喜欢

热点阅读