Skip to main content

CREATE TYPE

The CREATE TYPE statement defines a new type in the catalog.

Examples​

Create a simple ENUM type:

SQL
CREATE TYPE mood AS ENUM ('happy', 'sad', 'curious');

Create a simple STRUCT type:

SQL
CREATE TYPE many_things AS STRUCT(k INTEGER, l VARCHAR);

Create a simple UNION type:

SQL
CREATE TYPE one_thing AS UNION(number INTEGER, string VARCHAR);

Create a TUPLE type, whose fields have no names:

SQL
CREATE TYPE point_pair AS TUPLE(INTEGER, INTEGER);

Create a type alias:

SQL
CREATE TYPE x_index AS INTEGER;

Move a type to another schema:

SQL
CREATE TYPE vibe AS ENUM ('chill', 'hyped');
ALTER TYPE vibe SET SCHEMA archive;
SELECT 'hyped'::archive.vibe AS vibe;
 vibe
-------
 hyped

ALTER TYPE ... SET SCHEMA needs the CREATE privilege on the target schema, which must not already hold a type, table or view of that name. Moving a type into the schema it is already in changes nothing. A type that a column or another object uses can't be moved.

Syntax​

Syntax

The CREATE TYPE clause defines a new data type available to this SereneDB instance. These new types can then be inspected in the sdb_types table.

Every table and view also has a row type with its own name, as in PostgreSQL, so a type cannot take the name of a table or view in the same schema, and a table or view cannot take the name of a type there; renaming into such a name fails the same way. Indexes and sequences have no row type, so their names never clash with a type's.

Limitations​

  • Extending types to support custom operators (such as the PostgreSQL && operator) is not possible via plain SQL.

  • The CREATE TYPE clause does not support the OR REPLACE modifier.