Для чего предназначены домены:
DROP SCHEMA tmp CASCADE;
CREATE SCHEMA tmp;
SET search_path=tmp;
CREATE DOMAIN gender CHAR(1)
CHECK (value IN ( 'F' , 'M' ) )
;
CREATE TABLE persons
( pname VARCHAR
, gend tmp.gender
);
INSERT INTO persons( pname, gend) VALUES ('Alice', 'F') ,('Bob', 'M') ;
INSERT INTO persons( pname) VALUES ('HAL') ;
INSERT INTO persons( pname, gend) VALUES ('Maurice', 'Q') ;
SELECT * FROM persons;
Вывод:
DROP SCHEMA
CREATE SCHEMA
SET
CREATE DOMAIN
CREATE TABLE
INSERT 0 2
INSERT 0 1
ERROR: value for domain gender violates check constraint "gender_check"
pname | gend
-------+------
Alice | F
Bob | M
HAL |
(3 rows)