【发布时间】:2020-11-03 22:29:57
【问题描述】:
我有一个 postgres 数据库模式,其中包含我需要删除的数十个表。我基本上需要删除我的模式(abcd)中名称中带有“组”一词的所有表。如果不手动进入并为每个脚本编写放置脚本,我该如何做到这一点?想知道在 postgres sql 中是否有一些简单的方法可以做到这一点?或者也许使用 python?
drop table abcd.group%;
【问题讨论】:
-
select * from pg_class where relnamespace = 'abcd'::regnamespace and relname ilike 'group%'将为您提供以组开头的表格。如果您想在名称中的任何位置分组,则使用“%group%”。然后,您可以循环使用 Python 或 Postgres 函数。
标签: sql postgresql