title: Getting referenced tables in Postgres
body: <p>I have a list of foreign keys. I'd like to find out the tables where these FK's point to and the actual key the point to. </p>
  
  <p>I've got a list of FK's like so:</p>
  
  <pre><code>columnName0, columnName1, columnName2
  </code></pre>
  
  <p>Foreign key references</p>
  
  <ul>
  <li><code>columnName0</code> references <code>table0.idTable0</code> </li>
  <li><code>columnName1</code> references <code>table1.idTable1</code> </li>
  <li><code>columnName2</code> references <code>table2.idTable2</code> </li>
  </ul>
  
  <p>Some sample tables:</p>
  
  <p><strong>Table0</strong>:</p>
  
  <pre><code>idTable0, PK
  name
  </code></pre>
  
  <p><strong>Table1</strong>:</p>
  
  <pre><code>idTable1, PK
  age
  </code></pre>
  
  <p><strong>Table2</strong>:</p>
  
  <pre><code>idTable2, PK
  createdOn
  </code></pre>
  
  <p>A sample result:</p>
  
  <pre><code>| column      | referenced_column | referenced_table |
  |-------------|-------------------|------------------|
  | columnName0 | idTable0          | table0           |
  | columnName1 | idTable1          | table1           |
  | columnName2 | idTable2          | table2           |
  </code></pre>
  
  <p>I'm trying to translate something I do in MySQL like this:</p>
  
  <pre><code>SELECT DISTINCT
      COLUMN_NAME AS column,
      REFERENCED_COLUMN_NAME AS referenced_column,
      REFERENCED_TABLE_NAME AS referenced_table
  FROM 
      INFORMATION_SCHEMA.KEY_COLUMN_USAGE
  WHERE 
      COLUMN_NAME IN (?);
  </code></pre>
  
  <p>I'm going to have to use straight-up queries (unfortunately, no stored procedures).</p>