sql中生成随机字符串的function

create or replace function random_string(integer)
returns text as
$body$
   select array_to_string(array(select substring('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' FROM (ceil(random()*62))::int FOR 1) FROM generate_series(1, $1)), '');
$body$
language sql volatile;

 

posted @ 2017-05-25 16:18  growthofmonkey  阅读(529)  评论(0编辑  收藏  举报