title: What is the best way to enforce a 'subset' relationship with integrity constraints
body: <p>For example, given 3 tables:</p>
  
  <ul>
  <li>gastropod</li>
  <li>snail</li>
  <li>slug</li>
  </ul>
  
  <p>and assuming we want to enforce that</p>
  
  <ol>
  <li>every row in 'gastropod' has exactly one corresponding row in 'snail' or 'slug' (but not both)</li>
  <li>every row in 'slug' has exactly one corresponding row in 'gastropod'</li>
  <li>every row in 'snail' has exactly one corresponding row in 'gastropod'</li>
  </ol>
  
  <p>what is the best way to set up my schema to enforce these constraints?</p>
  
  <p>I've provide one possible answer for postgres, and I am particularly interested in solutions for postgres and Oracle, but would also be interested to see solutions for other RDBMSs</p>
  
  <p>EDIT<br>
  For reference, SO questions from from answers/comments below addressing similar problems:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/332602/maintaining-subclass-integrity-in-a-relational-database">Maintaining subclass integrity in a relational database</a></li>
  <li><a href="https://stackoverflow.com/questions/4969133/database-design-problem">Database design - articles, blog posts, photos, stories</a></li>
  <li><a href="https://stackoverflow.com/questions/5466163/same-data-from-different-entities-in-database-best-practice-phone-numbers-exa">Same data from different entities in Database - Best Practice - Phone numbers example</a></li>
  </ul>