title: How to enforce unique key across tables?
body: <p>I am using PostgreSQL 12 and PostGIS.</p>
  <h2>The Behaviour I want</h2>
  <p>I have a table <code>LOCATIONS</code> which contains geographic data and a <code>ROWID</code> as Primary Key. I also have a table <code>VALUES</code> which contains arbitrary values. I want to map each entry in <code>VALUES</code> to either no or a single location. I can easily do this with a foreign key in <code>VALUES</code> referencing <code>LOCATIONS.ROWID</code>.</p>
  <h2>The problem</h2>
  <p>The issue I have is that my location data is spread across multiple tables (which I can't change). Is there a way to <strong>add a field to <code>VALUES</code> that references exactly one row under one of the location tables?</strong></p>
  <p>I think this would require a unique identifier across multiple location tables. However, I do not know how to achieve this, while not relying on the correctness of inserted data.</p>
  <h2>Table Format for clarification</h2>
  <h3><code>VALUES</code></h3>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>rowid</th>
  <th>value</th>
  <th>geoID</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>0</td>
  <td>42</td>
  <td>0</td>
  </tr>
  <tr>
  <td>1</td>
  <td>69</td>
  <td>1</td>
  </tr>
  </tbody>
  </table>
  </div><h3><code>LOCATIONS A</code></h3>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>rowid</th>
  <th>name</th>
  <th>geoID</th>
  <th>geometry</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>0</td>
  <td>USA</td>
  <td>0</td>
  <td>POLYGON(...)</td>
  </tr>
  <tr>
  <td>1</td>
  <td>UK</td>
  <td>2</td>
  <td>POLYGON(...)</td>
  </tr>
  </tbody>
  </table>
  </div><h3><code>LOCATIONS B</code></h3>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>rowid</th>
  <th>name</th>
  <th>geoID</th>
  <th>geometry</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>0</td>
  <td>NYC</td>
  <td>1</td>
  <td>POLYGON(...)</td>
  </tr>
  <tr>
  <td>1</td>
  <td>LA</td>
  <td>3</td>
  <td>POLYGON(...)</td>
  </tr>
  </tbody>
  </table>
  </div>