导出出错
create extension "uuid-ossp"
删除所有表
DO $$ DECLARE r RECORD; BEGIN FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE'; END LOOP; END $$;
删除所有schema
create or replace function del_schema() returns void as $$ -- 定义函数内变量 declare rec varchar; begin -- 遍历所有 schema for rec in execute 'SELECT nspname FROM pg_namespace where nspname like ''a%'' ' loop -- 输出变量值 raise notice ' %' ,rec ; -- 执行删除 schema execute ' drop schema ' || rec; end loop; return ; end $$ language 'plpgsql'; -- 执行函数 select del_schema();
--------------------华丽分割线
清空表数据
DO $$ DECLARE r RECORD; BEGIN FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP EXECUTE 'DELETE FROM ' || quote_ident(r.tablename); END LOOP; END $$;
连接进入数据库,执行上述存储过程语句