循环插入
DO $$ DECLARE tmp RECORD; BEGIN FOR tmp IN select distinct id from test LOOP INSERT INTO test1 (id,role_code,privilege_code,space_id) VALUES (FLOOR(random() * 2147483646),'COMMON_USER','test',tmp.space_id); END LOOP; END $$ ;