head	1.35;
access;
symbols
	REL9_0_0:1.35
	REL9_1_ALPHA1:1.35
	REL9_0_RC1:1.35
	REL9_0_BETA4:1.35
	REL9_0_STABLE:1.35.0.2
	REL9_0_BETA3:1.35
	REL9_0_BETA2:1.35
	REL7_4_29:1.16
	REL8_0_25:1.20.4.1
	REL8_1_21:1.26
	REL8_2_17:1.29
	REL8_3_11:1.31
	REL8_4_4:1.32
	REL9_0_BETA1:1.34
	REL9_0_ALPHA5_BRANCH:1.33.0.8
	REL9_0_ALPHA5:1.33
	REL7_4_28:1.16
	REL8_0_24:1.20.4.1
	REL8_1_20:1.26
	REL8_2_16:1.29
	REL8_3_10:1.31
	REL8_4_3:1.32
	REL9_0_ALPHA4:1.33
	REL9_0_ALPHA4_BRANCH:1.33.0.6
	REL8_5_ALPHA3:1.33
	REL8_5_ALPHA3_BRANCH:1.33.0.4
	REL7_4_27:1.16
	REL8_0_23:1.20.4.1
	REL8_1_19:1.26
	REL8_2_15:1.29
	REL8_3_9:1.31
	REL8_4_2:1.32
	REL8_5_ALPHA2:1.33
	REL8_5_ALPHA2_BRANCH:1.33.0.2
	REL7_4_26:1.16
	REL8_0_22:1.20.4.1
	REL8_1_18:1.26
	REL8_2_14:1.29
	REL8_3_8:1.31
	REL8_4_1:1.32
	REL8_5_ALPHA1:1.32
	REL8_5_ALPHA1_BRANCH:1.32.0.4
	REL8_4_STABLE:1.32.0.2
	REL8_4_0:1.32
	REL8_4_RC2:1.32
	REL8_4_RC1:1.32
	REL8_4_BETA2:1.32
	REL8_4_BETA1:1.32
	REL7_4_25:1.16
	REL8_0_21:1.20.4.1
	REL8_1_17:1.26
	REL8_2_13:1.29
	REL8_3_7:1.31
	REL7_4_24:1.16
	REL8_0_20:1.20.4.1
	REL8_1_16:1.26
	REL8_2_12:1.29
	REL8_3_6:1.31
	REL7_4_23:1.16
	REL8_0_19:1.20.4.1
	REL8_1_15:1.26
	REL8_2_11:1.29
	REL8_3_5:1.31
	REL7_4_22:1.16
	REL8_0_18:1.20.4.1
	REL8_1_14:1.26
	REL8_2_10:1.29
	REL8_3_4:1.31
	REL7_4_21:1.16
	REL8_0_17:1.20.4.1
	REL8_1_13:1.26
	REL8_2_9:1.29
	REL8_3_3:1.31
	REL7_4_20:1.16
	REL8_0_16:1.20.4.1
	REL8_1_12:1.26
	REL8_2_8:1.29
	REL8_3_2:1.31
	REL8_2_7:1.29
	REL8_3_1:1.31
	REL8_3_STABLE:1.31.0.2
	REL8_3_0:1.31
	REL8_3_RC2:1.31
	REL7_3_21:1.6.2.2
	REL7_4_19:1.16
	REL8_0_15:1.20.4.1
	REL8_1_11:1.26
	REL8_2_6:1.29
	REL8_3_RC1:1.31
	REL8_3_BETA4:1.31
	REL8_3_BETA3:1.31
	REL8_3_BETA2:1.31
	REL8_3_BETA1:1.31
	REL7_3_20:1.6.2.2
	REL7_4_18:1.16
	REL8_0_14:1.20.4.1
	REL8_1_10:1.26
	REL8_2_5:1.29
	REL7_3_19:1.6.2.2
	REL7_4_17:1.16
	REL8_0_13:1.20.4.1
	REL8_1_9:1.26
	REL8_2_4:1.29
	REL8_0_12:1.20.4.1
	REL8_1_8:1.26
	REL8_2_3:1.29
	REL7_3_18:1.6.2.2
	REL7_4_16:1.16
	REL8_0_11:1.20.4.1
	REL8_1_7:1.26
	REL8_2_2:1.29
	REL8_0_10:1.20.4.1
	REL8_1_6:1.26
	REL8_2_1:1.29
	REL7_4_15:1.16
	REL7_3_17:1.6.2.2
	REL8_2_STABLE:1.29.0.2
	REL8_2_0:1.29
	REL8_2_RC1:1.29
	REL8_2_BETA3:1.29
	REL8_2_BETA2:1.29
	REL8_1_5:1.26
	REL8_0_9:1.20.4.1
	REL7_4_14:1.16
	REL7_3_16:1.6.2.2
	REL8_2_BETA1:1.29
	REL7_3_15:1.6.2.2
	REL7_4_13:1.16
	REL8_0_8:1.20.4.1
	REL8_1_4:1.26
	REL7_3_14:1.6.2.2
	REL7_4_12:1.16
	REL8_0_7:1.20.4.1
	REL8_1_3:1.26
	REL7_3_13:1.6.2.2
	REL7_4_11:1.16
	REL8_0_6:1.20.4.1
	REL8_1_2:1.26
	REL7_3_12:1.6.2.2
	REL7_4_10:1.16
	REL8_0_5:1.20.4.1
	REL8_1_1:1.26
	REL8_1_STABLE:1.26.0.2
	REL8_1_0:1.26
	REL8_1_0RC1:1.24
	REL8_1_0BETA4:1.24
	REL8_1_0BETA3:1.24
	REL7_3_11:1.6.2.2
	REL7_4_9:1.16
	REL8_0_4:1.20.4.1
	REL8_1_0BETA2:1.22
	REL8_1_0BETA1:1.22
	REL7_3_10:1.6.2.2
	REL7_4_8:1.16
	REL8_0_3:1.20.4.1
	REL8_0_2:1.20
	REL7_3_9:1.6.2.2
	REL7_4_7:1.16
	REL8_0_1:1.20
	REL8_0_STABLE:1.20.0.4
	REL8_0_0:1.20.0.2
	REL8_0_0RC5:1.20
	REL8_0_0RC4:1.20
	REL8_0_0RC3:1.19
	REL8_0_0RC2:1.19
	REL8_0_0RC1:1.19
	REL8_0_0BETA5:1.19
	REL8_0_0BETA4:1.19
	REL7_4_6:1.16
	REL7_3_8:1.6.2.2
	REL8_0_0BETA3:1.19
	REL8_0_0BETA2:1.19
	REL7_4_5:1.16
	REL7_3_7:1.6.2.2
	REL7_4_4:1.16
	REL8_0_0BETA1:1.19
	REL7_4_3:1.16
	REL7_4_2:1.16
	REL7_3_6:1.6.2.2
	REL7_4_1:1.16
	REL7_3_5:1.6.2.2
	REL7_4:1.16
	REL7_4_RC2:1.16
	REL7_4_STABLE:1.16.0.2
	REL7_4_RC1:1.16
	REL7_4_BETA5:1.16
	REL7_4_BETA4:1.16
	REL7_4_BETA3:1.15
	REL7_4_BETA2:1.13
	WIN32_DEV:1.13.0.2
	REL7_4_BETA1:1.13
	REL7_3_4:1.6.2.2
	REL7_3_2:1.6.2.1
	REL7_3_STABLE:1.6.0.2;
locks; strict;
comment	@# @;


1.35
date	2010.05.29.19.06.16;	author momjian;	state Exp;
branches;
next	1.34;

1.34
date	2010.04.03.07.22.58;	author petere;	state Exp;
branches;
next	1.33;

1.33
date	2009.09.18.05.00.41;	author petere;	state Exp;
branches;
next	1.32;

1.32
date	2008.11.14.10.22.46;	author petere;	state Exp;
branches;
next	1.31;

1.31
date	2007.02.01.00.28.18;	author momjian;	state Exp;
branches;
next	1.30;

1.30
date	2007.01.31.23.26.03;	author momjian;	state Exp;
branches;
next	1.29;

1.29
date	2006.09.16.00.30.17;	author momjian;	state Exp;
branches;
next	1.28;

1.28
date	2006.04.05.22.11.54;	author tgl;	state Exp;
branches;
next	1.27;

1.27
date	2005.12.25.01.41.15;	author neilc;	state Exp;
branches;
next	1.26;

1.26
date	2005.11.04.23.14.02;	author petere;	state Exp;
branches;
next	1.25;

1.25
date	2005.11.01.21.09.50;	author tgl;	state Exp;
branches;
next	1.24;

1.24
date	2005.09.23.02.01.35;	author momjian;	state Exp;
branches;
next	1.23;

1.23
date	2005.09.22.23.56.46;	author momjian;	state Exp;
branches;
next	1.22;

1.22
date	2005.05.02.01.52.50;	author neilc;	state Exp;
branches;
next	1.21;

1.21
date	2005.05.01.15.57.59;	author tgl;	state Exp;
branches;
next	1.20;

1.20
date	2005.01.04.00.39.53;	author tgl;	state Exp;
branches
	1.20.4.1;
next	1.19;

1.19
date	2004.08.08.02.05.32;	author tgl;	state Exp;
branches;
next	1.18;

1.18
date	2004.08.08.01.49.30;	author momjian;	state Exp;
branches;
next	1.17;

1.17
date	2003.11.29.19.51.38;	author pgsql;	state Exp;
branches;
next	1.16;

1.16
date	2003.09.22.00.16.57;	author petere;	state Exp;
branches;
next	1.15;

1.15
date	2003.09.09.18.28.52;	author tgl;	state Exp;
branches;
next	1.14;

1.14
date	2003.08.31.17.32.22;	author petere;	state Exp;
branches;
next	1.13;

1.13
date	2003.04.22.10.08.08;	author petere;	state Exp;
branches
	1.13.2.1;
next	1.12;

1.12
date	2003.03.25.16.15.39;	author petere;	state Exp;
branches;
next	1.11;

1.11
date	2003.02.13.05.32.42;	author momjian;	state Exp;
branches;
next	1.10;

1.10
date	2003.01.19.00.13.29;	author momjian;	state Exp;
branches;
next	1.9;

1.9
date	2002.12.12.20.35.07;	author tgl;	state Exp;
branches;
next	1.8;

1.8
date	2002.11.21.23.34.43;	author petere;	state Exp;
branches;
next	1.7;

1.7
date	2002.11.15.02.50.05;	author momjian;	state Exp;
branches;
next	1.6;

1.6
date	2002.09.20.03.39.15;	author momjian;	state Exp;
branches
	1.6.2.1;
next	1.5;

1.5
date	2002.04.23.02.07.15;	author tgl;	state Exp;
branches;
next	1.4;

1.4
date	2002.03.20.19.43.28;	author tgl;	state Exp;
branches;
next	1.3;

1.3
date	2002.03.19.02.18.13;	author momjian;	state Exp;
branches;
next	1.2;

1.2
date	2002.03.07.16.35.33;	author momjian;	state dead;
branches;
next	1.1;

1.1
date	2002.03.06.20.34.44;	author momjian;	state Exp;
branches;
next	;

1.6.2.1
date	2002.11.21.23.31.57;	author petere;	state Exp;
branches;
next	1.6.2.2;

1.6.2.2
date	2003.02.13.05.32.58;	author momjian;	state Exp;
branches;
next	;

1.13.2.1
date	2003.09.07.04.36.44;	author momjian;	state Exp;
branches;
next	;

1.20.4.1
date	2005.05.02.01.56.16;	author neilc;	state Exp;
branches;
next	;


desc
@@


1.35
log
@Document that NOT NULL domain constraints are not always honored.
@
text
@<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.34 2010/04/03 07:22:58 petere Exp $
PostgreSQL documentation
-->

<refentry id="SQL-CREATEDOMAIN">
 <refmeta>
  <refentrytitle>CREATE DOMAIN</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>CREATE DOMAIN</refname>
  <refpurpose>define a new domain</refpurpose>
 </refnamediv>

 <indexterm zone="sql-createdomain">
  <primary>CREATE DOMAIN</primary>
 </indexterm>

 <refsynopsisdiv>
<synopsis>
CREATE DOMAIN <replaceable class="parameter">name</replaceable> [ AS ] <replaceable class="parameter">data_type</replaceable>
    [ DEFAULT <replaceable>expression</replaceable> ]
    [ <replaceable class="PARAMETER">constraint</replaceable> [ ... ] ]

<phrase>where <replaceable class="PARAMETER">constraint</replaceable> is:</phrase>

[ CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ]
{ NOT NULL | NULL | CHECK (<replaceable class="PARAMETER">expression</replaceable>) }
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>CREATE DOMAIN</command> creates a new domain.  A domain is
   essentially a data type with optional constraints (restrictions on
   the allowed set of values).
   The user who defines a domain becomes its owner.
  </para>

  <para>
   If a schema name is given (for example, <literal>CREATE DOMAIN
   myschema.mydomain ...</>) then the domain is created in the
   specified schema.  Otherwise it is created in the current schema.
   The domain name must be unique among the types and domains existing
   in its schema.
  </para>

  <para>
   Domains are useful for abstracting common constraints on fields into
   a single location for maintenance.  For example, several tables might
   contain email address columns, all requiring the same CHECK constraint
   to verify the address syntax.
   Define a domain rather than setting up each table's constraint
   individually.
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

    <variablelist>
     <varlistentry>
      <term><replaceable class="parameter">name</replaceable></term>
      <listitem>
       <para>
        The name (optionally schema-qualified) of a domain to be created.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">data_type</replaceable></term>
      <listitem>
       <para>
        The underlying data type of the domain. This can include array
        specifiers.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><literal>DEFAULT <replaceable>expression</replaceable></literal></term>

      <listitem>
       <para>
        The <literal>DEFAULT</> clause specifies a default value for
        columns of the domain data type.  The value is any
        variable-free expression (but subqueries are not allowed).
        The data type of the default expression must match the data
        type of the domain.  If no default value is specified, then
        the default value is the null value.
       </para>

       <para>
        The default expression will be used in any insert operation
        that does not specify a value for the column.  If a default
        value is defined for a particular column, it overrides any
        default associated with the domain.  In turn, the domain
        default overrides any default value associated with the
        underlying data type.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><literal>CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable></literal></term>
      <listitem>
       <para>
        An optional name for a constraint.  If not specified,
        the system generates a name.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><literal>NOT NULL</></term>
      <listitem>
       <para>
        Values of this domain are normally prevented from being null.
        However, it is still possible for a domain with this constraint
        to take a null value if it is assigned a matching domain type
        that has become null, e.g. via a LEFT OUTER JOIN, or
        <command>INSERT INTO tab (domcol) VALUES ((SELECT domcol FROM
        tab WHERE false))</command>.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><literal>NULL</></term>
      <listitem>
       <para>
        Values of this domain are allowed to be null.  This is the default.
       </para>

       <para>
        This clause is only intended for compatibility with
        nonstandard SQL databases.  Its use is discouraged in new
        applications.
       </para>
      </listitem>
     </varlistentry>

   <varlistentry>
    <term><literal>CHECK (<replaceable class="PARAMETER">expression</replaceable>)</literal></term>
    <listitem>
     <para>
      <literal>CHECK</> clauses specify integrity constraints or tests
      which values of the domain must satisfy.
      Each constraint must be an expression
      producing a Boolean result.  It should use the key word <literal>VALUE</>
      to refer to the value being tested.
     </para>

     <para>
      Currently, <literal>CHECK</literal> expressions cannot contain
      subqueries nor refer to variables other than <literal>VALUE</>.
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

 <refsect1>
  <title>Examples</title>

  <para>
   This example creates the <type>us_postal_code</type> data type and
   then uses the type in a table definition.  A regular expression test
   is used to verify that the value looks like a valid US postal code:

<programlisting>
CREATE DOMAIN us_postal_code AS TEXT
CHECK(
   VALUE ~ '^\\d{5}$'
OR VALUE ~ '^\\d{5}-\\d{4}$'
);

CREATE TABLE us_snail_addy (
  address_id SERIAL PRIMARY KEY,
  street1 TEXT NOT NULL,
  street2 TEXT,
  street3 TEXT,
  city TEXT NOT NULL,
  postal us_postal_code NOT NULL
);
</programlisting>
  </para>
 </refsect1>

 <refsect1 id="SQL-CREATEDOMAIN-compatibility">
  <title>Compatibility</title>

  <para>
   The command <command>CREATE DOMAIN</command> conforms to the SQL
   standard.
  </para>
 </refsect1>

 <refsect1 id="SQL-CREATEDOMAIN-see-also">
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-alterdomain"></member>
   <member><xref linkend="sql-dropdomain"></member>
  </simplelist>
 </refsect1>

</refentry>
@


1.34
log
@Remove unnecessary xref endterm attributes and title ids

The endterm attribute is mainly useful when the toolchain does not support
automatic link target text generation for a particular situation.  In  the
past, this was required by the man page tools for all reference page links,
but that is no longer the case, and it now actually gets in the way of
proper automatic link text generation.  The only remaining use cases are
currently xrefs to refsects.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.33 2009/09/18 05:00:41 petere Exp $
d124 6
a129 1
        Values of this domain are not allowed to be null.
@


1.33
log
@Easier to translate psql help

Instead of requiring translators to translate the entire SQL command
synopses, change create_help.pl to only require them to translate the
placeholders, and paste those into the synopsis using a printf mechanism.
Make some small updates to the markup to make it easier to parse.

Note: This causes msgmerge of gettext 0.17 to segfault.  You will need
the patch from https://savannah.gnu.org/bugs/?27474 to make it work.
msgmerge usually only runs on babel.postgresql.org, however.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.32 2008/11/14 10:22:46 petere Exp $
d8 1
a8 1
  <refentrytitle id="sql-createdomain-title">CREATE DOMAIN</refentrytitle>
d204 2
a205 2
   <member><xref linkend="sql-alterdomain" endterm="sql-alterdomain-title"></member>
   <member><xref linkend="sql-dropdomain" endterm="sql-dropdomain-title"></member>
@


1.32
log
@Set SQL man pages to be section 7 by default, and only transform them to
another section if required by the platform (instead of the old way of
building them in section "l" and always transforming them to the
platform-specific section).

This speeds up the installation on common platforms, and it avoids some
funny business with the man page tools and build process.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.31 2007/02/01 00:28:18 momjian Exp $
d25 1
a25 1
    [ DEFAULT <replaceable>expression</> ]
d28 1
a28 1
where <replaceable class="PARAMETER">constraint</replaceable> is:
@


1.31
log
@Consistenly use colons before '<programlisting>' blocks, where
appropriate.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.30 2007/01/31 23:26:03 momjian Exp $
d9 1
@


1.30
log
@Update reference documentation on may/can/might:

Standard English uses "may", "can", and "might" in different ways:

        may - permission, "You may borrow my rake."

        can - ability, "I can lift that log."

        might - possibility, "It might rain today."

Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice.  Similarly, "It may crash" is better stated, "It might crash".
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.29 2006/09/16 00:30:17 momjian Exp $
d169 1
a169 1
   is used to verify that the value looks like a valid US postal code.
@


1.29
log
@Remove emacs info from footer of SGML files.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.28 2006/04/05 22:11:54 tgl Exp $
d79 1
a79 1
        The underlying data type of the domain. This may include array
@


1.28
log
@Fix a bunch of problems with domains by making them use special input functions
that apply the necessary domain constraint checks immediately.  This fixes
cases where domain constraints went unchecked for statement parameters,
PL function local variables and results, etc.  We can also eliminate existing
special cases for domains in places that had gotten it right, eg COPY.

Also, allow domains over domains (base of a domain is another domain type).
This almost worked before, but was disallowed because the original patch
hadn't gotten it quite right.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.27 2005/12/25 01:41:15 neilc Exp $
a208 17

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->
@


1.27
log
@Minor doc tweak: "NOT NULL" is redundant with "SERIAL" in example.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.26 2005/11/04 23:14:02 petere Exp $
d38 4
a41 2
   <command>CREATE DOMAIN</command> creates a new data domain.  The
   user who defines a domain becomes its owner.
d53 6
a58 5
   Domains are useful for abstracting common fields between tables
   into a single location for maintenance.  For example, an email address
   column may be used in several tables, all with the same properties.
   Define a domain and use that rather than setting up each table's
   constraints individually. 
a59 12

  <caution>
  <para>
   At present, declaring a function result value as a domain 
   is pretty dangerous, because none of the procedural languages enforce domain constraints 
   on their results.  You'll need to make sure that the function code itself
   respects the constraints.  In <application>PL/pgSQL</>, one possible
   workaround is to explicitly cast the result value to the domain type
   when you return it.  <application>PL/pgSQL</> does not enforce domain
   constraints for local variables within functions, either.
  </para>
  </caution>
d150 1
a150 1
      producing a Boolean result.  It should use the name <literal>VALUE</>
d179 6
a184 6
  address_id SERIAL PRIMARY KEY
, street1 TEXT NOT NULL
, street2 TEXT
, street3 TEXT
, city TEXT NOT NULL
, postal us_postal_code NOT NULL
@


1.26
log
@Spellchecking run, final cleanups
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.25 2005/11/01 21:09:50 tgl Exp $
d23 1
a23 1
CREATE DOMAIN <replaceable class="parameter">name</replaceable> [AS] <replaceable class="parameter">data_type</replaceable>
d188 1
a188 1
  address_id SERIAL NOT NULL PRIMARY KEY
@


1.25
log
@Make an editorial pass over the reference pages.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.24 2005/09/23 02:01:35 momjian Exp $
d61 1
a61 1
   is pretty dangerous, because none of the PLs enforce domain constraints 
@


1.24
log
@Attached patch takes a swing at improving the autovacuum wording in
maintenance.sgml.

Robert Treat

[ Also fix create domain markup.]
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.23 2005/09/22 23:56:46 momjian Exp $
d58 1
a58 1
  <note>
d60 1
a60 1
   Keep in mind also that declaring a function result value as a domain 
d62 5
a66 1
   on their results.
d68 1
a68 1
  </note>
@


1.23
log
@Add warning about DOMAINs.

David Fetter
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.22 2005/05/02 01:52:50 neilc Exp $
d55 1
a55 3
   constraints individually. <note>Keep in mind also that declaring a
   function result value as a domain is pretty dangerous, because none of
   the PLs enforce domain constraints on their results.</note>
d57 8
@


1.22
log
@Add some missing "See Also" entries to the domain-related SQL reference
pages. From Robert Treat.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.21 2005/05/01 15:57:59 tgl Exp $
d51 7
a57 4
   Domains are useful for abstracting common fields between tables into
   a single location for maintenance.  For example, an email address column may be used
   in several tables, all with the same properties.  Define a domain and
   use that rather than setting up each table's constraints individually.
@


1.21
log
@Fix incorrect backslashing in regexp example, per Robert Treat.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.20 2005/01/04 00:39:53 tgl Exp $
a205 1

@


1.20
log
@More minor updates and copy-editing.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.19 2004/08/08 02:05:32 tgl Exp $
d170 2
a171 2
   VALUE ~ '^\d{5}$'
OR VALUE ~ '^\d{5}-\d{4}$'
@


1.20.4.1
log
@Backport fix for correct quoting in CREATE DOMAIN example. Per Robert
Treat.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.20 2005/01/04 00:39:53 tgl Exp $
d170 2
a171 2
   VALUE ~ '^\\d{5}$'
OR VALUE ~ '^\\d{5}-\\d{4}$'
@


1.19
log
@Minor editorialization on example --- I think that the use of dollar
quoting in this case is just needless obscurantism.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.18 2004/08/08 01:49:30 momjian Exp $
d66 1
a66 1
	The name (optionally schema-qualified) of a domain to be created.
d76 1
a76 1
	specifiers.
d199 1
@


1.18
log
@This patch adds an example to the CREATE DOMAIN docs.

David Fetter
@
text
@d2 1
a2 1
$PostgreSQL: pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.17 2003/11/29 19:51:38 pgsql Exp $
d164 2
a165 1
    then uses the type in a table definition:
a168 1
NOT NULL
d170 2
a171 2
   VALUE ~ $pc$^\d{5}$$pc$
OR VALUE ~ $pc$^\d{5}-\d{4}$$pc$
d180 1
a180 1
, postal us_postal_code
@


1.17
log
@
$Header: -> $PostgreSQL Changes ...
@
text
@d2 1
a2 1
$PostgreSQL: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.16 2003/09/22 00:16:57 petere Exp $
d163 3
a165 2
   This example creates the <type>country_code</type> data type and then uses the
   type in a table definition:
d167 15
a181 2
CREATE DOMAIN country_code char(2) NOT NULL;
CREATE TABLE countrylist (id integer, country country_code);
@


1.16
log
@Make the SQL command synopses appear less random.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.15 2003/09/09 18:28:52 tgl Exp $
@


1.15
log
@Remove a bunch of content-free Diagnostics sections, as per previous
discussion.  (Still have some work to do editing the remainder.)
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.14 2003/08/31 17:32:22 petere Exp $
d23 2
a24 2
CREATE DOMAIN <replaceable class="parameter">domainname</replaceable> [AS] <replaceable class="parameter">data_type</replaceable>
    [ DEFAULT <replaceable>default_expr</> ]
d63 1
a63 1
      <term><replaceable class="parameter">domainname</replaceable></term>
d82 1
a82 1
      <term><literal>DEFAULT <replaceable>default_expr</replaceable></literal></term>
@


1.14
log
@Add/edit index entries.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.13 2003/04/22 10:08:08 petere Exp $
a152 15
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

 <refsect1>
  <title>Diagnostics</title>

  <variablelist>
   <varlistentry>
    <term><computeroutput>CREATE DOMAIN</computeroutput></term>
    <listitem>
     <para>
      Message returned if the domain was successfully created.
@


1.13
log
@More editing of reference pages.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.12 2003/03/25 16:15:39 petere Exp $
d16 4
@


1.13.2.1
log
@Update this branch to match CVS head, includes WIN32 improvements.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.14 2003/08/31 17:32:22 petere Exp $
a15 4

 <indexterm zone="sql-createdomain">
  <primary>CREATE DOMAIN</primary>
 </indexterm>
@


1.12
log
@Merge documentation into one book.  (Build with "make html".)  Replace
vague cross-references with real links.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.11 2003/02/13 05:32:42 momjian Exp $
d8 1
a8 3
  <refentrytitle id="sql-createdomain-title">
   CREATE DOMAIN
  </refentrytitle>
d11 1
d13 2
a14 6
  <refname>
   CREATE DOMAIN
  </refname>
  <refpurpose>
   define a new domain
  </refpurpose>
d16 1
d18 1
a18 4
  <refsynopsisdivinfo>
   <date>2002-02-24</date>
  </refsynopsisdivinfo>
  <synopsis>
d27 2
a28 1
  </synopsis>
d30 26
a55 8
  <refsect2 id="R2-SQL-CREATEDOMAIN-1">
   <refsect2info>
    <date>2002-02-24</date>
   </refsect2info>
   <title>
    Parameters
   </title>
   <para>
d78 2
a79 2
      <term><literal>DEFAULT
      <replaceable>default_expr</replaceable></literal></term>
d83 5
a87 5
	columns of the domain data type.  The value
        is any variable-free expression (but subselects are not allowed).
	The
        data type of the default expression must match the data type of the
        domain.
d91 7
a97 13
        The default expression will be used in any insert operation that
        does not specify a value for the column.  If there is no default
        for a domain, then the default is NULL.
       </para>

       <note>
        <para>
         If a default value is specified for a particular column, it
	 overrides any default associated with the domain.  In turn,
	 the domain default overrides any default value associated with
	 the underlying data type.
        </para>
       </note>
d115 1
a115 1
        Values of this domain are not allowed to be NULL.  
d124 1
a124 1
        Values of this domain are allowed to be NULL.  This is the default.
d128 2
a129 2
        This clause is only available for compatibility with
        non-standard SQL databases.  Its use is discouraged in new
d148 1
a148 1
      subselects nor refer to variables other than <literal>VALUE</>.
a149 1

d152 2
d155 2
a156 12
    </variablelist>
   </para>
  </refsect2>

  <refsect2 id="R2-SQL-CREATEDOMAIN-2">
   <refsect2info>
    <date>2002-02-24</date>
   </refsect2info>
   <title>
    Outputs
   </title>
   <para>
d158 10
a167 45
    <variablelist>
     <varlistentry>
      <term><computeroutput>
CREATE DOMAIN
       </computeroutput></term>
      <listitem>
       <para>
	Message returned if the domain is successfully created.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </para>
  </refsect2>
 </refsynopsisdiv>

 <refsect1 id="R1-SQL-CREATEDOMAIN-1">
  <refsect1info>
   <date>2002-02-24</date>
  </refsect1info>
  <title>
   Description
  </title>

  <para>
   <command>CREATE DOMAIN</command>  allows  the user to register a new
   data domain with <productname>PostgreSQL</> for use in the
   current data base.   The user  who  defines  a domain becomes its owner.
  </para>

  <para>
   If a schema name is given (for example, <literal>CREATE DOMAIN
   myschema.mydomain ...</>) then the domain is created in the
   specified schema.  Otherwise it is created in the current schema (the one
   at the front of the search path; see <literal>CURRENT_SCHEMA()</>).
   The domain name must be unique among the types and domains existing
   in its schema.
  </para>

  <para>
   Domains are useful for abstracting common fields between tables into
   a single location for maintenance.  An email address column may be used
   in several tables, all with the same properties.  Define a domain and
   use that rather than setting up each table's constraints individually.
  </para>
d172 1
d178 1
a178 1
CREATE TABLE countrylist (id INT4, country country_code);
d180 9
@


1.11
log
@> > They work the same as table constraints with in-line declaration (no
> > comma).
>
> OK. But the documentation implies there is a comma, so it should probably
> get chenged then.

Yes, it should. (attached)

[ Backpatched to 7.3.X too.]

Rod Taylor
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.10 2003/01/19 00:13:29 momjian Exp $
a60 2
        Refer to the &cite-user; for further
        information about data types and arrays.
a224 1
   <member>&cite-programmer;</member>
@


1.10
log
@This patch includes a lot of minor cleanups to the SGML documentation,
including:

- replacing all the appropriate usages of <citetitle>PostgreSQL
...</citetitle> with &cite-user;, &cite-admin;, and so on

- fix an omission in the EXECUTE documentation

- add some more text to the EXPLAIN documentation

- improve the PL/PgSQL RETURN NEXT documentation (more work to do here)

- minor markup fixes


Neil Conway
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.9 2002/12/12 20:35:07 tgl Exp $
d28 1
a28 1
    [ <replaceable class="PARAMETER">constraint</replaceable> [, ... ] ]
@


1.9
log
@Preliminary code review for domain CHECK constraints patch: add documentation,
make VALUE a non-reserved word again, use less invasive method of passing
ConstraintTestValue into transformExpr, fix problems with nested constraint
testing, do correct thing with NULL result from a constraint expression,
remove memory leak.  Domain checks still need much more work if we are going
to allow ALTER DOMAIN, however.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.8 2002/11/21 23:34:43 petere Exp $
d61 1
a61 1
        Refer to the <citetitle>User's Guide</citetitle> for further
d227 1
a227 1
   <member><citetitle>PostgreSQL Programmer's Guide</citetitle></member>
@


1.8
log
@Fixups for man pages
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.7 2002/11/15 02:50:05 momjian Exp $
d33 1
a33 1
{ NOT NULL | NULL }
d130 19
@


1.7
log
@Add DOMAIN check constraints.

Rod Taylor
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.6 2002/09/20 03:39:15 momjian Exp $
d8 1
a8 1
  <refentrytitle id="sql-createdomian-title">
d207 1
a207 1
   <member><xref linkend="sql-dropdomain"></member>
@


1.6
log
@This patch corrects a minor mis-statement in the CREATE DOMAIN docs,
pointed out by Chris KL on -hackers a little while ago -- NOT NULL !=
CHECK xxx IS NOT NULL.

Neil Conway
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.5 2002/04/23 02:07:15 tgl Exp $
a199 10
  </para>
 </refsect1>

 <refsect1 id="SQL-CREATEDOMAIN-compatibility">
  <title>Compatibility</title>

  <para>
   SQL99 defines CREATE DOMAIN, but says that the only allowed constraint
   type is CHECK constraints.  CHECK constraints for domains are not yet
   supported by <productname>PostgreSQL</productname>.
@


1.6.2.1
log
@Fixups for man pages
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.6 2002/09/20 03:39:15 momjian Exp $
d8 1
a8 1
  <refentrytitle id="sql-createdomain-title">
d217 1
a217 1
   <member><xref linkend="sql-dropdomain" endterm="sql-dropdomain-title"></member>
@


1.6.2.2
log
@> > They work the same as table constraints with in-line declaration (no
> > comma).
>
> OK. But the documentation implies there is a comma, so it should probably
> get chenged then.

Yes, it should. (attached)

[ Backpatched to 7.3.X too.]

Rod Taylor
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/create_domain.sgml,v 1.6.2.1 2002/11/21 23:31:57 petere Exp $
d28 1
a28 1
    [ <replaceable class="PARAMETER">constraint</replaceable> [ ... ] ]
@


1.5
log
@Update SQL-command reference pages for schema features.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.4 2002/03/20 19:43:28 tgl Exp $
d111 1
a111 3
        Values of this domain are not allowed to be NULL.  This is
        equivalent to the column constraint <literal>CHECK (<replaceable
        class="PARAMETER">column</replaceable> NOT NULL)</literal>.
@


1.4
log
@Code review for DOMAIN patch.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.3 2002/03/19 02:18:13 momjian Exp $
d50 1
a50 1
	The name of a domain to be created.
d59 2
a60 1
        The data type of the domain. This may include array specifiers.
d171 12
a182 6
   <command>CREATE DOMAIN</command>  allows  the user to register a new user data
   domain with PostgreSQL for use in the current data base.   The
   user  who  defines  a domain becomes its owner.
   <replaceable class="parameter">domainname</replaceable> is
   the name of the new type and must  be  unique  within  the
   types and domains defined for this database.
@


1.3
log
@Add DOMAIN support.  Includes manual pages and regression tests, from
Rod Taylor.
@
text
@d2 1
a2 1
$Header$
d26 6
a31 1
CREATE DOMAIN <replaceable class="parameter">domainname</replaceable> <replaceable class="parameter">data_type</replaceable>  [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [, ... ] ]
d33 1
a33 5
{ NOT NULL | NULL <!-- |  UNIQUE | PRIMARY KEY |
  CHECK (<replaceable class="PARAMETER">expression</replaceable>) |
  REFERENCES <replaceable class="PARAMETER">reftable</replaceable> [ ( <replaceable class="PARAMETER">refcolumn</replaceable> ) ] [ MATCH FULL | MATCH PARTIAL ]
    [ ON DELETE <replaceable class="parameter">action</replaceable> ] [ ON UPDATE <replaceable class="parameter">action</replaceable> ] --> }
<!-- [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] -->
d71 4
a74 4
        The <literal>DEFAULT</> clause assigns a default data value for
        the column whose column definition it appears within.  The value
        is any variable-free expression (subselects and cross-references
        to other columns in the current table are not allowed).  The
d81 1
a81 1
        does not specify a value for the domain.  If there is no default
d87 4
a90 1
         The default of a column will be tested before that of the domain.
d100 1
a100 1
        An optional name for a domain.  If not specified,
d110 1
a110 1
        The column is not allowed to contain NULL values.  This is
d121 1
a121 1
        The column is allowed to contain NULL values. This is the default.
d182 1
a182 1
   use that rather than setting up each tables constraints individually.
d202 3
a204 3
   This <command>CREATE DOMAIN</command> command is a
   <productname>PostgreSQL</productname> extension.  CHECK and FOREIGN KEY
   constraints are currently unsupported.
@


1.2
log
@Back out domain patch until it works properly.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_domain.sgml,v 1.1 2002/03/06 20:34:44 momjian Exp $
@


1.1
log
@Ok.  Updated patch attached.

- domain.patch -> source patch against pgsql in cvs
- drop_domain.sgml and create_domain.sgml -> New doc/src/sgml/ref docs

- dominfo.txt -> basic domain related queries I used for testing
[ ADDED TO /doc]

Enables domains of array elements -> CREATE DOMAIN dom int4[3][2];

Uses a typbasetype column to describe the origin of the domain.

Copies data to attnotnull rather than processing in execMain().

Some documentation differences from earlier.

If this is approved, I'll start working on pg_dump, and a \dD <domain>
option in psql, and regression tests.  I don't really feel like doing
those until the system table structure settles for pg_type.


CHECKS when added, will also be copied to to the table attributes.  FK
Constraints (if I ever figure out how) will be done similarly.  Both
will lbe handled by MergeDomainAttributes() which is called shortly
before MergeAttributes().

Rod Taylor
@
text
@d2 1
a2 1
$Header$
@
