Making a domain conditional on other values in the table How can I define or change a domain based on another attribute value?

F.e. domain for salary is a numeric value > 500. But if a date the person was hired > January 1st, 2013, then the salary must be > 1000.
I wouldn't try to solve that with a DOMAIN since that cannot reference other columns. Use a CHECK constraint instead:

ALTER TABLE foo ADD CONSTRAINT foo_min_salary
CHECK (salary &gt; 1000 OR hired &lt; '2013-01-01' AND salary &gt; 500);



Define the column NOT NULL in addition to disallow NULL values.
Using the IS0 8601 format for the date, which is valid with any locale and the recommended form.
Note how I inverted your logic to arrive at a simpler form.
I wrote hired &lt; '2013-01-01' on purpose, suspecting that your phrase hired &gt; January 1st, 2013 is off by one.
Be aware of operator precedence. AND binds before OR.


If you are building on a domain that already demands value &gt; 500, you can simplify the CHECK constraint to:

ALTER TABLE foo ADD CONSTRAINT foo_min_salary
CHECK (salary &gt; 1000 OR hired &lt; '2013-01-01');