Create Type

Defines a new data type for use in the database.


CREATE TYPE typename ( INPUT = input_function, OUTPUT = output_function
      , INTERNALLENGTH = { internallength | VARIABLE }
    [ , EXTERNALLENGTH = { externallength | VARIABLE } ]
    [ , DEFAULT = "default" ]
    [ , ELEMENT = element ] [ , DELIMITER = delimiter ]
    [ , SEND = send_function ] [ , RECEIVE = receive_function ]
    [ , ALIGNMENT = alignment ]
    [ , STORAGE = storage ] )



The name of the new type being created, which may be up to 30 characters in length. All type names must be unique within a database, and may not begin with an underscore (which is reserved for implicit array types).


The internal length of the new type, in bytes.


The optional external (displayed) length of the new type.


The name of the new type’s input function. You must have already defined the function using CREATE FUNCTION, and it must act to convert data of the type’s external form into the type’s internal form.


The name of the new type’s output function. This function must convert data of the type’s internal form into its displayable form.


The data type of individual array elements which this type addresses, if you intend to create an array type manually. The element must be fixed-length data type.


The value delimiter for the implicitly created array associated with the new type (typename[]).


The default value for the new data type. If you do ...

Get Practical PostgreSQL now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.