--创建删除所有表的存储过程
CREATE OR REPLACE FUNCTION delAllTable()
RETURNS void
AS
$BODY$
DECLARE
tmp VARCHAR(512);
DECLARE names CURSOR FOR
select tablename from pg_tables where tableowner='wxdch';
BEGIN
FOR stmt IN names LOOP
tmp := 'DROP TABLE '|| quote_ident(stmt.tablename) || ' CASCADE;';
RAISE NOTICE 'notice: %', tmp;
EXECUTE 'DROP TABLE '|| quote_ident(stmt.tablename) || ' CASCADE;';
END LOOP;
RAISE NOTICE 'finished .....';
END;
$BODY$ LANGUAGE 'plpgsql' VOLATILE;
--执行存储过程
select * from delAllTable() as temp;
--创建删除所有序列号的存储过程
CREATE OR REPLACE FUNCTION delAllSeq()
RETURNS void AS
$BODY$
DECLARE
tmp VARCHAR(512);
DECLARE names CURSOR FOR
select * from pg_class where relowner=(select usesysid from pg_user where usename='wxdch') and relkind='S' ;
BEGIN
FOR stmt IN names LOOP
tmp := 'DROP sequence '|| quote_ident(stmt.relname) || ' CASCADE;';
RAISE NOTICE 'notice: %', tmp;
EXECUTE 'DROP sequence '|| quote_ident(stmt.relname) || ' CASCADE;';
END LOOP;
RAISE NOTICE 'finished .....';
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
ALTER FUNCTION delAllSeq() OWNER TO postgres;
--执行存储过程
select * from delAllSeq() as temp;
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。