DROP OWNED
是用于删除特定角色拥有的数据库对象的DDL。
DROP OWNED
添加于 PostgreSQL 8.2。
更改历史
- PostgreSQL 14
DROP OWNED BY CURRENT_ROLE
语法添加 (提交 45b98057)
- PostgreSQL 9.5
DROP OWNED BY { CURRENT_USER | SESSION_USER }
语法添加 (提交 31eae602)
- PostgreSQL 8.2
- 添加 (提交 cec3b0a9)
示例
DROP OWNED
的基本用法示例
postgres=# DROP OWNED BY bar; DROP OWNED
如果存在任何依赖项(例如外键关系),则必须提供 CASCADE 关键字
postgres=# DROP OWNED BY baz; ERROR: cannot drop table foo because other objects depend on it DETAIL: constraint bar_foo_id_fkey on table bar depends on table foo HINT: Use DROP ... CASCADE to drop the dependent objects too.
提供不存在的角色名称
postgres=# DROP OWNED BY baz; ERROR: role "baz" does not exist
参考
- PostgreSQL 文档: DROP OWNED