Last active
March 31, 2016 17:11
-
-
Save aj0strow/5a07f2ddcad324c4dac2c4095c821999 to your computer and use it in GitHub Desktop.
conditiona sql constraint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ADD CONSTRAINT with_old_syntax CHECK (status <> 'closed' OR agent_id IS NOT NULL); | |
ADD CONSTRAINT with_new_syntax CHECK (agent_id IS NOT NULL) WHERE (status = 'closed'); | |
-- generically it would map as follows | |
CHECK (check_condition) WHERE (where_condition) | |
CHECK (NOT (where_condition) OR check_condition) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment