Skip to main content
A user-defined ENUM data type consists of a set of enumerated, static values.

Syntax

To declare a new enumerated data type, use CREATE TYPE:
where <name is the name of the new type, and <value1, <value2>, ... are string literals that make up the type’s set of static values. You can qualify the <name of an enumerated type with a database and schema name (e.g., db.typename). After the type is created, it can only be referenced from the database that contains the type. To show all ENUM types in the database, including all ENUMS created implicitly for multi-region databases, use SHOW ENUMS:
To modify an ENUM type, use ALTER TYPE:
where <value is a string literal to add to the existing list of type values. You can also use ALTER TYPE to rename types, rename type values, set a type’s schema, or change the type owner’s role specification. To drop the type, use DROP TYPE:

Required privileges

  • To create a type in a database, a user must have the CREATE privilege on the database.
  • To drop a type, a user must be the owner of the type.
  • To alter a type, a user must be the owner of the type.
  • To grant privileges on a type, a user must have the GRANT privilege and the privilege that they want to grant.
  • To create an object that depends on a type, a user must have the USAGE privilege on the type.

Example

Supported casting and conversion

ENUM data type values can be cast to STRINGs. Values can be cast explicitly or implicitly. For example, the following SELECT statements are equivalent:

Comparing enumerated types

To compare two enumerated types, you must explicitly cast both types as STRINGs. For example:

See also