Skip to main content
The CREATE TYPE statement creates a new type in a database. After the type is created, it can only be referenced from the database that contains the type. The following user-defined data types can be created with this statement: The CREATE TYPE statement performs a schema change. For more information about how online schema changes work in CockroachDB, see Online Schema Changes.

Synopsis

create_type syntax diagram

Parameters

Required privileges

  • To create a type, the user must have the CREATE privilege on the parent database and the schema in which the type is being created.
  • To use a user-defined type in a table (e.g., when defining a column’s type), the user must have the USAGE privilege on the type.

Example

Create an enumerated data type

Use the statements below to create an ENUM data type.
To see all user-defined data types, use SHOW TYPES:
To see the values accepted by the underlying ENUM data type, use SHOW ENUMS:

Create a composite data type

Use the statements below to create a composite data type:
Insert 10,000 randomly generated values of type mypoint:

See also