PostgreSQL随机测试数据产生脚本

begin;
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;  
create table person(id int,name text, age int);
insert into person select generate_series(1,1000000),random_string(floor(random()*20+10)),floor(random()*60+15);
drop function random_string(integer);
select pg_size_pretty(pg_relation_size('person'));
commit;
posted @ 2017-12-11 20:04  bingo711x  阅读(819)  评论(0编辑  收藏  举报