Create Type

Defines a new data type for use in the database.

Synopsis

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 ]
    [ , PASSEDBYVALUE ]
    [ , ALIGNMENT = alignment ]
    [ , STORAGE = storage ] )

Parameters

typename

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).

internallength

The internal length of the new type, in bytes.

externallength

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

input_function

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.

output_function

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

element

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.

delimiter

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

default

The default value for the new data type. ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.