Switch to: V12V11V10V9V8V7V6V5

CREATE TYPE

Defines a new user defined data type.

AS ENUM

[NEW in 5.0]

user_defined_type_definition
    :    CREATE [OR REPLACE] TYPE [IF NOT EXISTS] type_name 
             AS {ENUM | ENUM8 | ENUM16} character_string_literal_list [, locale_character_string_literal_lists]
 
character_string_literal_list
    :    ( [character_string_literal, ...] )
 
locale_character_string_literal_lists
    :    locale_character_string_literal_list [, ...]
 
locale_character_string_literal_list
    :    locale_name COLON character_string_literal_list
 
locale_name			
    : character_string_literal;

Arguments

type_name

The name of a type to be created.

OR REPLACE

This clause forces dropping of an existed type with the specified name and then new type will be create as specified. So effectively this is the same as:

DROP TYPE TX;
CREATE TYPE TX ...;

IF NOT EXISTS

The IF NOT EXISTS option allows you suppress the error message in case if such type already exists. This makes it much easier to perform SQL dumps without interruption.

ENUM8/ENUM16

This parameter allows you to specify the size of enum field, and therefore, its capacity. Enum8 can handle up to 255 values. Enum16 - up to 65535.

Description

This form of CREATE TYPE creates an enumerated (enum) type, as described in Enumerated Types.

Examples

CREATE TYPE DayOfWeek AS ENUM8( 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ); 
-- with some additional locales:
--
CREATE TYPE DayOfWeek 
   AS ENUM8  ( 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ),
   'ru':( 'Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота' ),
    'de':( 'Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag' )
-- can be an empty list on start
--
CREATE TYPE DayOfWeek AS ENUM();

See Also