DROP TYPE

用于删除自定义数据类型的 SQL 命令

DROP TYPE 是一个用于删除自定义数据类型的 DDL 命令。

DROP TYPE 始终存在于 PostgreSQL 中。

变更历史

示例

基本的 DROP TYPE 执行示例

postgres=# DROP TYPE unused_type;
DROP TYPE

删除带有依赖项的类型

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

尝试删除不存在的类型

postgres=# DROP TYPE no_such_type;
ERROR:  type "no_such_type" does not exist

安全地尝试删除可能不存在的类型

postgres=# DROP TYPE IF EXISTS no_such_type;
NOTICE:  type "no_such_type" does not exist, skipping
DROP TYPE

无法删除 PostgreSQL 的基本类型

postgres=# DROP TYPE pg_lsn;
ERROR:  cannot drop type pg_lsn because it is required by the database system

分类

数据类型, DDL, SQL 命令

另请参阅

CREATE TYPE, ALTER TYPE, pg_type

反馈

提交任何关于“DROP TYPE”的评论、建议或更正,请在此处 提交