Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/ref/alter_domain.sgml`
116c851452a7ee59fc9bba04c7be0955a2742ba17c97fa3c0000000100000fb0
<!--
doc/src/sgml/ref/alter_domain.sgml
PostgreSQL documentation
-->

<refentry id="sql-alterdomain">
 <indexterm zone="sql-alterdomain">
  <primary>ALTER DOMAIN</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>ALTER DOMAIN</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>ALTER DOMAIN</refname>
  <refpurpose>
   change the definition of a domain
  </refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
ALTER DOMAIN <replaceable class="parameter">name</replaceable>
    { SET DEFAULT <replaceable class="parameter">expression</replaceable> | DROP DEFAULT }
ALTER DOMAIN <replaceable class="parameter">name</replaceable>
    { SET | DROP } NOT NULL
ALTER DOMAIN <replaceable class="parameter">name</replaceable>
    ADD <replaceable class="parameter">domain_constraint</replaceable> [ NOT VALID ]
ALTER DOMAIN <replaceable class="parameter">name</replaceable>
    DROP CONSTRAINT [ IF EXISTS ] <replaceable class="parameter">constraint_name</replaceable> [ RESTRICT | CASCADE ]
ALTER DOMAIN <replaceable class="parameter">name</replaceable>
     RENAME CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> TO <replaceable class="parameter">new_constraint_name</replaceable>
ALTER DOMAIN <replaceable class="parameter">name</replaceable>
    VALIDATE CONSTRAINT <replaceable class="parameter">constraint_name</replaceable>
ALTER DOMAIN <replaceable class="parameter">name</replaceable>
    OWNER TO { <replaceable class="parameter">new_owner</replaceable> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER DOMAIN <replaceable class="parameter">name</replaceable>
    RENAME TO <replaceable class="parameter">new_name</replaceable>
ALTER DOMAIN <replaceable class="parameter">name</replaceable>
    SET SCHEMA <replaceable class="parameter">new_schema</replaceable>

<phrase>where <replaceable class="parameter">domain_constraint</replaceable> is:</phrase>

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

 <refsect1>
  <title>Description</title>

  <para>
   <command>ALTER DOMAIN</command> changes the definition of an existing domain.
   There are several sub-forms:
  </para>

  <variablelist>
   <varlistentry>
    <term><literal>SET</literal>/<literal>DROP DEFAULT</literal></term>
    <listitem>
     <para>
      These forms set or remove the default value for a domain. Note
      that defaults only apply to subsequent <command>INSERT</command>
      commands; they do not affect rows already in a table using the domain.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>SET</literal>/<literal>DROP NOT NULL</literal></term>
    <listitem>
     <para>
      These forms change whether a domain is marked to allow NULL
      values or to reject NULL values.  You can only <literal>SET NOT NULL</literal>
      when the columns using the domain contain no null values.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>ADD <replaceable class="parameter">domain_constraint</replaceable> [ NOT VALID ]</literal></term>
    <listitem>
     <para>
      This form adds a new constraint to a domain.
      When a new constraint is added to a domain, all columns using that
      domain will be checked against the newly added constraint.  These
      checks can be suppressed by adding the new constraint using the
      <literal>NOT VALID</literal> option; the constraint can later be made
      valid using <command>ALTER DOMAIN ... VALIDATE CONSTRAINT</command>.
      Newly inserted or updated rows are always checked against all
      constraints, even those marked <literal>NOT VALID</literal>.
      <literal>NOT VALID</literal> is only accepted for <literal>CHECK</literal> constraints.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>DROP

Title: ALTER DOMAIN
Summary
The ALTER DOMAIN command modifies the definition of an existing domain. It allows setting or dropping default values and NOT NULL constraints. It can also add new constraints to a domain, with an option to initially mark them as NOT VALID. The syntax and various sub-forms of the command are detailed.