CREATE TYPE Statement
The CREATE TYPE statement defines a new type in the catalog.
Examples
Create a simple ENUM type:
CREATE TYPE mood AS ENUM ('happy', 'sad', 'curious');Create a simple STRUCT type:
CREATE TYPE many_things AS STRUCT(k INTEGER, l VARCHAR);Create a simple UNION type:
CREATE TYPE one_thing AS UNION(number INTEGER, string VARCHAR);Create a type alias:
CREATE TYPE x_index AS INTEGER;Replace an existing type:
CREATE OR REPLACE TYPE mood AS ENUM ('cheerful', 'gloomy');Syntax
The CREATE TYPE clause defines a new data type available to this DuckDB instance.
Use the OR REPLACE modifier to redefine a type that already exists.
These new types can then be inspected in the duckdb_types table.
Limitations
- Extending types to support custom operators (such as the PostgreSQL
&&operator) is not possible via plain SQL. Instead, it requires adding additional C++ code. To do this, create an extension.