1ALTER DOMAIN(7) PostgreSQL 9.2.24 Documentation ALTER DOMAIN(7)
2
3
4
6 ALTER_DOMAIN - change the definition of a domain
7
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
23 ALTER DOMAIN name
24 RENAME TO new_name
25 ALTER DOMAIN name
26 SET SCHEMA new_schema
27
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
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.
100
101 RESTRICT
102 Refuse to drop the constraint if there are any dependent objects.
103 This is the default behavior.
104
105 new_name
106 The new name for the domain.
107
108 new_constraint_name
109 The new name for the constraint.
110
111 new_owner
112 The user name of the new owner of the domain.
113
114 new_schema
115 The new schema for the domain.
116
118 Currently, ALTER DOMAIN ADD CONSTRAINT and ALTER DOMAIN SET NOT NULL
119 will fail if the named domain or any derived domain is used within a
120 composite-type column of any table in the database. They should
121 eventually be improved to be able to verify the new constraint for such
122 nested columns.
123
125 To add a NOT NULL constraint to a domain:
126
127 ALTER DOMAIN zipcode SET NOT NULL;
128
129 To remove a NOT NULL constraint from a domain:
130
131 ALTER DOMAIN zipcode DROP NOT NULL;
132
133 To add a check constraint to a domain:
134
135 ALTER DOMAIN zipcode ADD CONSTRAINT zipchk CHECK (char_length(VALUE) = 5);
136
137 To remove a check constraint from a domain:
138
139 ALTER DOMAIN zipcode DROP CONSTRAINT zipchk;
140
141 To rename a check constraint on a domain:
142
143 ALTER DOMAIN zipcode RENAME CONSTRAINT zipchk TO zip_check;
144
145 To move the domain into a different schema:
146
147 ALTER DOMAIN zipcode SET SCHEMA customers;
148
150 ALTER DOMAIN conforms to the SQL standard, except for the OWNER,
151 RENAME, SET SCHEMA, and VALIDATE CONSTRAINT variants, which are
152 PostgreSQL extensions. The NOT VALID clause of the ADD CONSTRAINT
153 variant is also a PostgreSQL extension.
154
156 CREATE DOMAIN (CREATE_DOMAIN(7)), DROP DOMAIN (DROP_DOMAIN(7))
157
158
159
160PostgreSQL 9.2.24 2017-11-06 ALTER DOMAIN(7)