DROP TYPE

A DDL 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

Examples

Basic DROP TYPE execution:

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

Categories

Data type, DDL, SQL command

See also

CREATE TYPE, ALTER TYPE, pg_type