只适合PostgreSQL9.4及以上版本.
删除pg_pathman分区表和主表
do $$
begin
if( to_regclass('tablename') is not null ) then
if( (select 1 from pathman_config where partrel = 'tablename'::regclass) is not null) then
PERFORM drop_partitions('tablename'::regclass,true);
end if;
drop table tablename;
end if;
end;
$$;
判断pg_pathman分区表是否存在
首先要检查主表是否存在,当主表不存在时,如果没有判断’tablename’::regclass会出错.因此要分为二步完成.
if( to_regclass('tablename') is not null ) then
if( (select 1 from pathman_config where partrel = 'tablename'::regclass) is not null) then
end if;
end if;