Contents
DROP TYPE
An SQL command for removing a custom data type
DROP TYPE
is a DDL command for removing a custom data type
.
DROP TYPE
has always been present in PostgreSQL.
Change history
- PostgreSQL 8.2
IF EXISTS
clause added (commit daea4d8e)
- PostgreSQL 7.3
CASCADE
andRESTRICT
clauses added (commit 7c6df91d)
Examples
Basic DROP TYPE
execution example:
postgres=# DROP TYPE unused_type; DROP TYPE
Dropping a type with dependencies:
postgres=# DROP TYPE some_enum_type; ERROR: cannot drop type some_enum_type because other objects depend on it DETAIL: column thing_type of table thing depends on type some_enum_type postgres=# DROP TYPE some_enum_type CASCADE; NOTICE: drop cascades to column thing_type of table thing DROP TYPE
Attempting to drop a type which does not exist:
postgres=# DROP TYPE no_such_type; ERROR: type "no_such_type" does not exist
Safely attempting to drop a type which might not exist:
postgres=# DROP TYPE IF EXISTS no_such_type; NOTICE: type "no_such_type" does not exist, skipping DROP TYPE
References
- PostgreSQL documentation: DROP TYPE