我有这个定义的类型和表:
CREATE TYPE emp_role AS ENUM ('Manager','Developer','accountant','Secretary');
CREATE TABLE employees (
employee_id int NOT NULL UNIQUE,lastname text NOT NULL,firstname text NOT NULL,address text NOT NULL,hire_date date NOT NULL,salary numeric NOT NULL CHECK(salary > 1.500),emp_role emp_role,department_id int NOT NULL
);
我想在此表上创建一个约束而不更改其定义,该约束同时取决于属性hire_date
,salary
和emp_role
,例如,这意味着在emp_role
之后雇用的Manager
为2019-21-11
的员工不能有salary
比15.000
大,因此这样的查询应返回错误:
INSERT INTO employees VALUES(2,'foo','bar','foostreet','2019-12-20',18.0000,'Manager',3);
我不熟悉该怎么做