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

浙公网安备 33010602011771号