O'Reilly logo

Practical PostgreSQL by John C. Worsley, Joshua D. Drake

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. If you do ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required