我需要从后缀为“alpha”的数据库(Postgres)中删除表(多个表)。数据库中有近 500 个表,它们具有不同的后缀,我愿意仅删除后缀为“alpha”的表。
表名示例:inventory_20170312_alpha
你可以使用:
SELECT format('DROP TABLE IF EXISTS %s;' ,
(SELECT string_agg(table_name, ',')
FROM INFORMATION_SCHEMA.TABLES WHERE table_name LIKE '%alpha'));
警告!我假设其他表没有 FK。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句