1ALTER DOMAIN(7)          PostgreSQL 11.6 Documentation         ALTER DOMAIN(7)
2
3
4

NAME

6       ALTER_DOMAIN - change the definition of a domain
7

SYNOPSIS

9       ALTER DOMAIN name
10           { SET DEFAULT expression | DROP DEFAULT }
11       ALTER DOMAIN name
12           { SET | DROP } NOT NULL
13       ALTER DOMAIN name
14           ADD domain_constraint [ NOT VALID ]
15       ALTER DOMAIN name
16           DROP CONSTRAINT [ IF EXISTS ] constraint_name [ RESTRICT | CASCADE ]
17       ALTER DOMAIN name
18            RENAME CONSTRAINT constraint_name TO new_constraint_name
19       ALTER DOMAIN name
20           VALIDATE CONSTRAINT constraint_name
21       ALTER DOMAIN name
22           OWNER TO { new_owner | CURRENT_USER | SESSION_USER }
23       ALTER DOMAIN name
24           RENAME TO new_name
25       ALTER DOMAIN name
26           SET SCHEMA new_schema
27

DESCRIPTION

29       ALTER DOMAIN changes the definition of an existing domain. There are
30       several sub-forms:
31
32       SET/DROP DEFAULT
33           These forms set or remove the default value for a domain. Note that
34           defaults only apply to subsequent INSERT commands; they do not
35           affect rows already in a table using the domain.
36
37       SET/DROP NOT NULL
38           These forms change whether a domain is marked to allow NULL values
39           or to reject NULL values. You can only SET NOT NULL when the
40           columns using the domain contain no null values.
41
42       ADD domain_constraint [ NOT VALID ]
43           This form adds a new constraint to a domain using the same syntax
44           as CREATE DOMAIN (CREATE_DOMAIN(7)). When a new constraint is added
45           to a domain, all columns using that domain will be checked against
46           the newly added constraint. These checks can be suppressed by
47           adding the new constraint using the NOT VALID option; the
48           constraint can later be made valid using ALTER DOMAIN ... VALIDATE
49           CONSTRAINT. Newly inserted or updated rows are always checked
50           against all constraints, even those marked NOT VALID.  NOT VALID is
51           only accepted for CHECK constraints.
52
53       DROP CONSTRAINT [ IF EXISTS ]
54           This form drops constraints on a domain. If IF EXISTS is specified
55           and the constraint does not exist, no error is thrown. In this case
56           a notice is issued instead.
57
58       RENAME CONSTRAINT
59           This form changes the name of a constraint on a domain.
60
61       VALIDATE CONSTRAINT
62           This form validates a constraint previously added as NOT VALID,
63           that is, verify that all data in columns using the domain satisfy
64           the specified constraint.
65
66       OWNER
67           This form changes the owner of the domain to the specified user.
68
69       RENAME
70           This form changes the name of the domain.
71
72       SET SCHEMA
73           This form changes the schema of the domain. Any constraints
74           associated with the domain are moved into the new schema as well.
75
76       You must own the domain to use ALTER DOMAIN. To change the schema of a
77       domain, you must also have CREATE privilege on the new schema. To alter
78       the owner, you must also be a direct or indirect member of the new
79       owning role, and that role must have CREATE privilege on the domain's
80       schema. (These restrictions enforce that altering the owner doesn't do
81       anything you couldn't do by dropping and recreating the domain.
82       However, a superuser can alter ownership of any domain anyway.)
83

PARAMETERS

85       name
86           The name (possibly schema-qualified) of an existing domain to
87           alter.
88
89       domain_constraint
90           New domain constraint for the domain.
91
92       constraint_name
93           Name of an existing constraint to drop or rename.
94
95       NOT VALID
96           Do not verify existing column data for constraint validity.
97
98       CASCADE
99           Automatically drop objects that depend on the constraint, and in
100           turn all objects that depend on those objects (see Section 5.13).
101
102       RESTRICT
103           Refuse to drop the constraint if there are any dependent objects.
104           This is the default behavior.
105
106       new_name
107           The new name for the domain.
108
109       new_constraint_name
110           The new name for the constraint.
111
112       new_owner
113           The user name of the new owner of the domain.
114
115       new_schema
116           The new schema for the domain.
117

NOTES

119       Currently, ALTER DOMAIN ADD CONSTRAINT, ALTER DOMAIN VALIDATE
120       CONSTRAINT, and ALTER DOMAIN SET NOT NULL will fail if the named domain
121       or any derived domain is used within a container-type column (a
122       composite, array, or range column) in any table in the database. They
123       should eventually be improved to be able to verify the new constraint
124       for such nested values.
125

EXAMPLES

127       To add a NOT NULL constraint to a domain:
128
129           ALTER DOMAIN zipcode SET NOT NULL;
130
131       To remove a NOT NULL constraint from a domain:
132
133           ALTER DOMAIN zipcode DROP NOT NULL;
134
135       To add a check constraint to a domain:
136
137           ALTER DOMAIN zipcode ADD CONSTRAINT zipchk CHECK (char_length(VALUE) = 5);
138
139       To remove a check constraint from a domain:
140
141           ALTER DOMAIN zipcode DROP CONSTRAINT zipchk;
142
143       To rename a check constraint on a domain:
144
145           ALTER DOMAIN zipcode RENAME CONSTRAINT zipchk TO zip_check;
146
147       To move the domain into a different schema:
148
149           ALTER DOMAIN zipcode SET SCHEMA customers;
150

COMPATIBILITY

152       ALTER DOMAIN conforms to the SQL standard, except for the OWNER,
153       RENAME, SET SCHEMA, and VALIDATE CONSTRAINT variants, which are
154       PostgreSQL extensions. The NOT VALID clause of the ADD CONSTRAINT
155       variant is also a PostgreSQL extension.
156

SEE ALSO

158       CREATE DOMAIN (CREATE_DOMAIN(7)), DROP DOMAIN (DROP_DOMAIN(7))
159
160
161
162PostgreSQL 11.6                      2019                      ALTER DOMAIN(7)
Impressum