Contents
DROP OWNED
An SQL command for dropping objects owned by a role
DROP OWNED
is a DDL for removing database objects owned by a particular role.
DROP OWNED
was added in PostgreSQL 8.2.
Change history
- PostgreSQL 14
DROP OWNED BY CURRENT_ROLE
syntax added (commit 45b98057)
- PostgreSQL 9.5
DROP OWNED BY { CURRENT_USER | SESSION_USER }
syntax added (commit 31eae602)
- PostgreSQL 8.2
- added (commit cec3b0a9)
Examples
Basic usage example for DROP OWNED
:
postgres=# DROP OWNED BY bar; DROP OWNED
If any dependencies such as foreign key relationships are present, the CASCADE keyword must be provided:
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.
Providing the name of a non-existent role:
postgres=# DROP OWNED BY baz; ERROR: role "baz" does not exist
References
- PostgreSQL documentation: DROP OWNED