underlying data type.
The underlying type must be collatable if <literal>COLLATE</literal>
is specified.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>DEFAULT <replaceable>expression</replaceable></literal></term>
<listitem>
<para>
The <literal>DEFAULT</literal> 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</literal></term>
<listitem>
<para>
Values of this domain are prevented from being null
(but see notes below).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>NULL</literal></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</literal> 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</literal>
to refer to the value being tested. Expressions evaluating
to TRUE or UNKNOWN succeed. If the expression produces a FALSE result,
an error is reported and the value is not allowed to be converted
to the domain type.
</para>
<para>
Currently, <literal>CHECK</literal> expressions cannot contain
subqueries nor refer to variables other than <literal>VALUE</literal>.
</para>
<para>
When a domain has multiple <literal>CHECK</literal> constraints,
they will be tested in alphabetical order by name.
(<productname>PostgreSQL</productname> versions before 9.5 did not honor any
particular firing order for <literal>CHECK</literal> constraints.)
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 id="sql-createdomain-notes">
<title>Notes</title>
<para>
Domain constraints, particularly <literal>NOT NULL</literal>, are checked when
converting a value to the domain type. It is possible for a column that
is nominally of the domain type to read as null despite there being such
a constraint. For example, this can happen in an outer-join query, if
the domain column is on the nullable side of the outer join. A