postgresql 批量删除模式中一些表

DO  $$
DECLARE names CURSOR FOR 
    select * from pg_tables where schemaname='riskzoning' and tablename like '%_clip' ;
BEGIN
  FOR stmt IN names LOOP
     EXECUTE 'DROP TABLE '|| quote_ident(stmt.tablename) || ' CASCADE;';
  END LOOP;
END;$$

  

使用正则匹配表

select * from pg_tables where schemaname='riskzoning' and  tablename SIMILAR TO '%_\d{13}' ;

 结果 : 匹配 xzq_gw_50108_1651054276357

posted @ 2022-05-10 10:00  qukaige  阅读(252)  评论(0编辑  收藏  举报