Skip to content

Instantly share code, notes, and snippets.

@aj0strow
Last active March 31, 2016 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aj0strow/5a07f2ddcad324c4dac2c4095c821999 to your computer and use it in GitHub Desktop.
Save aj0strow/5a07f2ddcad324c4dac2c4095c821999 to your computer and use it in GitHub Desktop.
conditiona sql constraint
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