Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/ref/create_type.sgml`
104a8d53c0caa34ece8335bee1928db74231258e0133e12d0000000100000faf
<!--
doc/src/sgml/ref/create_type.sgml
PostgreSQL documentation
-->

<refentry id="sql-createtype">
 <indexterm zone="sql-createtype">
  <primary>CREATE TYPE</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>CREATE TYPE</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>CREATE TYPE</refname>
  <refpurpose>define a new data type</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
CREATE TYPE <replaceable class="parameter">name</replaceable> AS
    ( [ <replaceable class="parameter">attribute_name</replaceable> <replaceable class="parameter">data_type</replaceable> [ COLLATE <replaceable>collation</replaceable> ] [, ... ] ] )

CREATE TYPE <replaceable class="parameter">name</replaceable> AS ENUM
    ( [ '<replaceable class="parameter">label</replaceable>' [, ... ] ] )

CREATE TYPE <replaceable class="parameter">name</replaceable> AS RANGE (
    SUBTYPE = <replaceable class="parameter">subtype</replaceable>
    [ , SUBTYPE_OPCLASS = <replaceable class="parameter">subtype_operator_class</replaceable> ]
    [ , COLLATION = <replaceable class="parameter">collation</replaceable> ]
    [ , CANONICAL = <replaceable class="parameter">canonical_function</replaceable> ]
    [ , SUBTYPE_DIFF = <replaceable class="parameter">subtype_diff_function</replaceable> ]
    [ , MULTIRANGE_TYPE_NAME = <replaceable class="parameter">multirange_type_name</replaceable> ]
)

CREATE TYPE <replaceable class="parameter">name</replaceable> (
    INPUT = <replaceable class="parameter">input_function</replaceable>,
    OUTPUT = <replaceable class="parameter">output_function</replaceable>
    [ , RECEIVE = <replaceable class="parameter">receive_function</replaceable> ]
    [ , SEND = <replaceable class="parameter">send_function</replaceable> ]
    [ , TYPMOD_IN = <replaceable class="parameter">type_modifier_input_function</replaceable> ]
    [ , TYPMOD_OUT = <replaceable class="parameter">type_modifier_output_function</replaceable> ]
    [ , ANALYZE = <replaceable class="parameter">analyze_function</replaceable> ]
    [ , SUBSCRIPT = <replaceable class="parameter">subscript_function</replaceable> ]
    [ , INTERNALLENGTH = { <replaceable class="parameter">internallength</replaceable> | VARIABLE } ]
    [ , PASSEDBYVALUE ]
    [ , ALIGNMENT = <replaceable class="parameter">alignment</replaceable> ]
    [ , STORAGE = <replaceable class="parameter">storage</replaceable> ]
    [ , LIKE = <replaceable class="parameter">like_type</replaceable> ]
    [ , CATEGORY = <replaceable class="parameter">category</replaceable> ]
    [ , PREFERRED = <replaceable class="parameter">preferred</replaceable> ]
    [ , DEFAULT = <replaceable class="parameter">default</replaceable> ]
    [ , ELEMENT = <replaceable class="parameter">element</replaceable> ]
    [ , DELIMITER = <replaceable class="parameter">delimiter</replaceable> ]
    [ , COLLATABLE = <replaceable class="parameter">collatable</replaceable> ]
)

CREATE TYPE <replaceable class="parameter">name</replaceable>
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>CREATE TYPE</command> registers a new data type for use in
   the current database.  The user who defines a type becomes its
   owner.
  </para>

  <para>
   If a schema name is given then the type is created in the specified
   schema.  Otherwise it is created in the current schema.  The type
   name must be distinct from the name of any existing type or domain
   in the same schema.  (Because tables have associated data types,
   the type name must also be distinct from the name of any existing
   table in the same schema.)
  </para>

  <para>
   There are five forms of <command>CREATE TYPE</command>, as shown in the
   syntax synopsis above.  They respectively create a <firstterm>composite
   type</firstterm>, an <firstterm>enum type</firstterm>, a <firstterm>range type</firstterm>, a
   <firstterm>base type</firstterm>, or a <firstterm>shell

Title: CREATE TYPE - Define a New Data Type
Summary
The `CREATE TYPE` command registers a new data type for use in the current database. The user who defines the type becomes its owner. The type name must be distinct from existing types or domains in the schema. There are five forms of `CREATE TYPE`: composite, enum, range, base, and shell.