title: Postgresql data validation checks based on table values
body: <p>I'm trying to create a database that tracks electrical cables.  Each cable contains 1 or more cores that are connected to terminals at each end.  The number of cores in each cable is defined in a table. </p>
  
  <pre><code>| number_of_cores  | cable_id
  |----------2-------|---1-----|
  </code></pre>
  
  <p>The core table is as follows</p>
  
  <pre><code>cable_no   | from_id | core_mark | to_id
  1001       |       1 | 1 Black   |     2
  1001       |       2 | 1 White   |     4
  </code></pre>
  
  <p>I want to create a check that will prevent another 1001 cable core from being inserted.</p>
  
  <p>Is this possible in postgresql?</p>
  
  <p>Ideally, if I tried to insert another 1001 cable with another unique core number, the error would be something like "all cores used on cable 1001"</p>
  
  <p>Thanks,</p>