编写postgresql函数执行循环copy命令导入大数据

CREATE OR REPLACE FUNCTION copyData()
  RETURNS boolean AS
$BODY$
DECLARE
i int;
begin     
i :=1; 
FOR i IN 1..9 LOOP
copy tb4_20130109012 to '/mnt/ramfs/weibo.tb4001w'; 
copy tb4_20130109012 from '/mnt/ramfs/weibo.tb4001w'; 
RAISE NOTICE 'i IS %', i;
END LOOP;
if i >1 then 
     return true;
   else 
     return false; 
   end if; 
end;    
$BODY$
language plpgsql;

执行下面命令,运行函数

SELECT *from copyData();

执行结果:

postgres=# SELECT *from copyData();
NOTICE:  i IS 1
NOTICE:  i IS 2
NOTICE:  i IS 3
NOTICE:  i IS 4
NOTICE:  i IS 5
NOTICE:  i IS 6
NOTICE:  i IS 7
NOTICE:  i IS 8
NOTICE:  i IS 9


 

posted on 2014-11-21 16:48  XIAO的博客  阅读(1490)  评论(0编辑  收藏  举报

导航