测试了下,速度确实快了很多:
修正下原文的插入语句:
DO $$
DECLARE
i INTEGER := 1;
identityId BIGINT := 200000000001;
BEGIN
  WHILE i < 50 LOOP
    identityId = identityId + 1;
  raise notice ‘%‘,i;
      -- INSERT 语句
      -- 将字符串转为 uuid cast (‘057b8c51-f62f-4260-bdbb-‘ || identityId as uuid)
	  --begin
	  INSERT INTO almart_all
select
	(select
		array_agg(j::date)
	 from generate_series(‘2015-12-10‘::date, ‘2015-12-14‘::date, ‘1 day‘::interval) as t(j)
	)[floor(random()*4)+1] as date_key,
	floor(random()*24) as hour_key,
	floor(random()*1000000)+1 as client_key,
	floor(random()*100000)+1 as item_key,
	floor(random()*20)+1 as account,
	floor(random()*10000)+1 as expense
from
	generate_series(1,50000,1)
commit;
							 
    i = i + 1;
  END LOOP;
END $$;
原文:https://www.cnblogs.com/qianxunman/p/13332368.html