title: Conditional PostgreSQL foreign key
body: <p>Is it possible in PostgreSQL to conditionally add a foreign key?</p>
  <p>Something like:<code>ALTER TABLE table1 ADD FOREIGN KEY (some_id) REFERENCES other_table WHERE some_id NOT IN (0,-1) AND some_id IS NOT NULL;</code></p>
  <p>Specifically, my reference table has all positive integers (1+) but the table I need to add the foreign key to can contain zero (0), null and negative one (-1) instead, all meaning something different.</p>
  <p>Notes:</p>
  <blockquote>
  <p><strong>I am fully aware that this is poor table design</strong>, but it was a clever trick built 10+ years ago when the features and resources we have available at this point did not exist.  This system is running hundreds of retail stores so going back and changing the method at this point could take months which we don't have.</p>
  <p>I can not use a trigger, <strong>this MUST be done with a foreign key</strong>.</p>
  </blockquote>