PostgreSQL DOMAIN Drop
DROP DOMAIN removes a domain. Only the owner of a domain can remove it
Syntax:
Examples:
Syntax:
DROP DOMAIN [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
parameter
|
Explanation
|
IF EXISTS
|
Do not throw an error if the domain does not exist. A notice is issued in this case.
|
name
|
The name (optionally schema-qualified) of an existing domain.
|
CASCADE
|
Automatically drop objects that depend on the domain (such as table columns).
|
RESTRICT
|
Refuse to drop the domain if any objects depend on it. This is the default
|
To remove the domain postal_code:
Step 1. list out the Dmain using "\dD"
postgres=# \dD List of domains Schema | Name | Type | Modifier | Check --------+-------------+-----------------------+-------------------------------------------+------------------------------------------------------------------ public | addrtype | character varying(90) | not null default 'N/A'::character varying | public | idxtype | integer | | CHECK (VALUE > 10 AND VALUE < 99) public | postal_code | text | | CHECK (VALUE ~ '^\d{5}$'::text OR VALUE ~ '^\d{5}-\d{4}$'::text) (3 rows)
Step 2.Now Let us Drop the Domain if you want to drop "addrtype" domain you need to specify "cascade" keyword otherwise it will throw errors here startingly i gave "drop domain addrtype" without "cascade" keyword for your understanding this will be throw error after that i gave "cascade" keyword why it throw error because other objects depend on it so use "CASCADE" to drop the dependent objects too
postgres=# drop domain addrtype; ERROR: cannot drop type addrtype because other objects depend on it DETAIL: table place column address depends on type addrtype HINT: Use DROP ... CASCADE to drop the dependent objects too.
Step 3.Now use drop domain with cascade option
postgres=# drop domain addrtype cascade; NOTICE: drop cascades to table place column address DROP DOMAIN
Step 4.Now check domain
postgres=# \dD List of domains Schema | Name | Type | Modifier | Check --------+-------------+---------+----------+------------------------------------------------------------------ public | idxtype | integer | | CHECK (VALUE > 10 AND VALUE < 99) public | postal_code | text | | CHECK (VALUE ~ '^\d{5}$'::text OR VALUE ~ '^\d{5}-\d{4}$'::text) (2 rows)
Comments
Post a Comment