DROP TYPE

This page documents the preview version (v2.21). Preview includes features under active development and is for development and testing only. For production, use the stable version (v2024.1). To learn more, see Versioning.

Synopsis

Use the DROP TYPE statement to remove a user-defined type from the database.

Syntax

drop_type ::= DROP TYPE [ IF EXISTS ] type_name [ , ... ] 
              [ CASCADE | RESTRICT ]

drop_type

DROPTYPEIFEXISTS,type_nameCASCADERESTRICT

Semantics

drop_type

type_name

Specify the name of the user-defined type to drop.

Examples

Simple example

yugabyte=# CREATE TYPE feature_struct AS (id INTEGER, name TEXT);
yugabyte=# DROP TYPE feature_struct;

IF EXISTS example

yugabyte=# DROP TYPE IF EXISTS feature_shell;

CASCADE example

yugabyte=# CREATE TYPE feature_enum AS ENUM ('one', 'two', 'three');
yugabyte=# CREATE TABLE feature_tab_enum (feature_col feature_enum);
yugabyte=# DROP TYPE feature_tab_enum CASCADE;

RESTRICT example

yugabyte=# CREATE TYPE feature_range AS RANGE (subtype=INTEGER);
yugabyte=# CREATE TABLE feature_tab_range (feature_col feature_range);
yugabyte=# -- The following should error:
yugabyte=# DROP TYPE feature_range RESTRICT;
yugabyte=# DROP TABLE feature_tab_range;
yugabyte=# DROP TYPE feature_range RESTRICT;

See also