当前位置:Gxlcms > 数据库问题 > Greenplum(PostgreSql)函数实现批量删除表

Greenplum(PostgreSql)函数实现批量删除表

时间:2021-07-01 10:21:17 帮助过:149人阅读

or replace function vppp.func_drop_tables() returns void as $body$ -- 注意schema名称 declare tmp varchar(512); -- 存放拼接文本 stmp record; -- 记录类型可用于保存查询结果 i int; -- 计数 begin i := 1; for stmp in (select tablename table_nam from pg_tables where tableowner = vppp and schemaname=vppp) loop -- 这里vppp也是schema,默认和owner相同 tmp := drop table vppp. || stmt.bale_nam || cascade;; --cascade表示级联删除 raise notice currentTable is : % ------%, stmt.table_nam, i; -- 打印一下信息,当前表名称和序号。 if stmt.table_nam <> A_T_Test -- 我的库里有一个测试用的表,删除动作跳过。 then raise notice drop______; -- execute tmp; -- 执行删除动作我这里注释掉,需要时再打开。 end if; i := i+1; end; $body$ language plpgsql volatile

 

代码是手打,本机也没有测试环境,如果有拼写错误请仔细检查一下。

Greenplum(PostgreSql)函数实现批量删除表

标签:sel   arch   --   current   拼接   测试环境   生产环境   表示   cascade   

人气教程排行