SELECT ceil(random()*(10000-1)+1) as num;SELECT floor(random()*(10000-1)+1) as num;SELECT trunc(random()*(10000-1)+1) as num;
获取100个1-10000之间的随机整数,可能会有重复数据
SELECT ceil(random()*(10000-1)+1) as num from generate_series(1,100);
获取100个1-10000之间的随机整数,没有重复数据
select num from generate_series(1,1000000) as t(num) orderby random() limit 10;
再介绍一个生成测试数据的方法,生成2000w数据,第一个整数,第二个8位文本
select id,substring(md5(id::varchar),2,8) from generate_series (1,2000000) as t(id)
select id,substring(md5(random()::varchar),2,8) from generate_series (1,2000000) as t(id)