ALTER DOMAIN modifies a in the current database.
The
ALTER DOMAIN statement performs a schema change. For more information about how online schema changes work in CockroachDB, refer to .Synopsis
Parameters
Required privileges
- To alter a domain, the user must be the owner of the domain.
- To set the schema of a domain, the user must also have the
CREATEon the new schema. - To alter the owner of a domain:
- The user executing the command must be a member of the new owner role.
- The new owner role must have the
CREATEprivilege on the schema the domain belongs to.
Examples
The examples use the following domain and table:Set a default value
The following statement sets a default value of1 for columns that use the order_qty domain:
Add a constraint
Existing data is validated before the constraint is applied. If a value in theorders table violates the new constraint, the statement returns an error:
NOT VALID, existing data is not validated and only newly inserted or updated values are checked:
convalidated column of pg_catalog.pg_constraint shows whether each domain constraint is validated:
Rename and drop a constraint
Rename the constraint added in the preceding example:Change the owner and schema
Create a role and make it the owner of the domain:Rename a domain
The following statement renames the domain, referencing it by its new schema-qualified name:Known limitations
ALTER DOMAIN ... VALIDATE CONSTRAINTis not supported. A constraint added withNOT VALIDcannot be validated later; to validate existing data, drop the constraint and add it withoutNOT VALID.- For additional limitations, refer to .

