DROP RULE 是用于移除规则的 DDL 命令。
DROP RULE 一直存在于 PostgreSQL 中,尽管它直到 PostgreSQL 6.4 版本才真正可用。
变更历史
- PostgreSQL 8.2
- 添加了
DROP RULE IF EXISTS ...语法(提交 bbcd0169)
- 添加了
- PostgreSQL 7.3
- PostgreSQL 6.4
- 使其可用(初始提交 15cb32d9)
示例
DROP RULE 的基本用法示例
postgres=# DROP RULE foo_insert_rule ON foo; DROP RULE
尝试删除一个不存在的规则
postgres=# DROP RULE foo_update_rule ON foo; ERROR: rule "foo_update_rule" for relation "foo" does not exist
安全地尝试删除可能不存在的规则
postgres=# DROP RULE IF EXISTS foo_insert_rule ON foo; NOTICE: rule "foo_insert_rule" for relation "foo" does not exist, skipping DROP RULE
参考资料
- PostgreSQL 文档: DROP RULE
