I have a table with id, external_id and country_code columns. I have two rules which I want the database to impose:
- Each External ID can only appear once per country code
- Each ID can only appear with at most one non-null External ID, and vice versa.
The first rule is easy enough - I add a unique multi-column index to external_id and country_code. How do I get it to impose the second?