3 PostgreSQL documentation
6 <refentry id=
"SQL-ALTERDOMAIN">
8 <refentrytitle id=
"sql-alterdomain-title">ALTER DOMAIN
</refentrytitle>
9 <manvolnum>7</manvolnum>
10 <refmiscinfo>SQL - Language Statements
</refmiscinfo>
14 <refname>ALTER DOMAIN
</refname>
16 change the definition of a domain
20 <indexterm zone=
"sql-alterdomain">
21 <primary>ALTER DOMAIN
</primary>
26 ALTER DOMAIN
<replaceable class=
"PARAMETER">name
</replaceable>
27 { SET DEFAULT
<replaceable class=
"PARAMETER">expression
</replaceable> | DROP DEFAULT }
28 ALTER DOMAIN
<replaceable class=
"PARAMETER">name
</replaceable>
29 { SET | DROP } NOT NULL
30 ALTER DOMAIN
<replaceable class=
"PARAMETER">name
</replaceable>
31 ADD
<replaceable class=
"PARAMETER">domain_constraint
</replaceable>
32 ALTER DOMAIN
<replaceable class=
"PARAMETER">name
</replaceable>
33 DROP CONSTRAINT
<replaceable class=
"PARAMETER">constraint_name
</replaceable> [ RESTRICT | CASCADE ]
34 ALTER DOMAIN
<replaceable class=
"PARAMETER">name
</replaceable>
35 OWNER TO
<replaceable class=
"PARAMETER">new_owner
</replaceable>
36 ALTER DOMAIN
<replaceable class=
"PARAMETER">name
</replaceable>
37 SET SCHEMA
<replaceable class=
"PARAMETER">new_schema
</replaceable>
42 <title>Description
</title>
45 <command>ALTER DOMAIN
</command> changes the definition of an existing domain.
46 There are several sub-forms:
51 <term>SET/DROP DEFAULT
</term>
54 These forms set or remove the default value for a domain. Note
55 that defaults only apply to subsequent
<command>INSERT
</command>
56 commands; they do not affect rows already in a table using the domain.
62 <term>SET/DROP NOT NULL
</term>
65 These forms change whether a domain is marked to allow NULL
66 values or to reject NULL values. You can only
<literal>SET NOT NULL<
/>
67 when the columns using the domain contain no null values.
73 <term>ADD
<replaceable class=
"PARAMETER">domain_constraint
</replaceable></term>
76 This form adds a new constraint to a domain using the same syntax as
77 <xref linkend=
"SQL-CREATEDOMAIN" endterm=
"SQL-CREATEDOMAIN-TITLE">.
78 This will only succeed if all columns using the domain satisfy the
85 <term>DROP CONSTRAINT
</term>
88 This form drops constraints on a domain.
97 This form changes the owner of the domain to the specified user.
103 <term>SET SCHEMA
</term>
106 This form changes the schema of the domain. Any constraints
107 associated with the domain are moved into the new schema as well.
114 You must own the domain to use
<command>ALTER DOMAIN<
/>.
115 To change the schema of a domain, you must also have
116 <literal>CREATE
</literal> privilege on the new schema.
117 To alter the owner, you must also be a direct or indirect member of the new
118 owning role, and that role must have
<literal>CREATE
</literal> privilege on
119 the domain's schema. (These restrictions enforce that altering the owner
120 doesn't do anything you couldn't do by dropping and recreating the domain.
121 However, a superuser can alter ownership of any domain anyway.)
126 <title>Parameters
</title>
131 <term><replaceable class=
"PARAMETER">name
</replaceable></term>
134 The name (possibly schema-qualified) of an existing domain to
141 <term><replaceable class=
"PARAMETER">domain_constraint
</replaceable></term>
144 New domain constraint for the domain.
150 <term><replaceable class=
"PARAMETER">constraint_name
</replaceable></term>
153 Name of an existing constraint to drop.
159 <term><literal>CASCADE
</literal></term>
162 Automatically drop objects that depend on the constraint.
168 <term><literal>RESTRICT
</literal></term>
171 Refuse to drop the constraint if there are any dependent
172 objects. This is the default behavior.
178 <term><replaceable class=
"PARAMETER">new_owner
</replaceable></term>
181 The user name of the new owner of the domain.
187 <term><replaceable class=
"PARAMETER">new_schema
</replaceable></term>
190 The new schema for the domain.
203 Currently,
<command>ALTER DOMAIN ADD CONSTRAINT<
/> and
204 <command>ALTER DOMAIN SET NOT NULL<
/> will fail if the named domain or
205 any derived domain is used within a composite-type column of any
206 table in the database. They should eventually be improved to be
207 able to verify the new constraint for such nested columns.
213 <title>Examples
</title>
216 To add a
<literal>NOT NULL
</literal> constraint to a domain:
218 ALTER DOMAIN zipcode SET NOT NULL;
220 To remove a
<literal>NOT NULL
</literal> constraint from a domain:
222 ALTER DOMAIN zipcode DROP NOT NULL;
227 To add a check constraint to a domain:
229 ALTER DOMAIN zipcode ADD CONSTRAINT zipchk CHECK (char_length(VALUE) =
5);
234 To remove a check constraint from a domain:
236 ALTER DOMAIN zipcode DROP CONSTRAINT zipchk;
241 To move the domain into a different schema:
243 ALTER DOMAIN zipcode SET SCHEMA customers;
248 <refsect1 id=
"SQL-ALTERDOMAIN-compatibility">
249 <title>Compatibility
</title>
252 <command>ALTER DOMAIN
</command> conforms to the
<acronym>SQL
</acronym>
254 except for the
<literal>OWNER<
/> and
<literal>SET SCHEMA<
/> variants,
255 which are
<productname>PostgreSQL
</productname> extensions.
259 <refsect1 id=
"SQL-ALTERDOMAIN-see-also">
260 <title>See Also
</title>
262 <simplelist type=
"inline">
263 <member><xref linkend=
"sql-createdomain" endterm=
"sql-createdomain-title"></member>
264 <member><xref linkend=
"sql-dropdomain" endterm=
"sql-dropdomain-title"></member>