title: PostgreSQL join across 2 databases
body: <p>I am new to PostgreSQL. I have 2 databases in PostgreSQL 9.0, db1 and db2, and with db2 I have read only access. I want to create a stored function that would be otherwise easily accomplished with a JOIN or a nested query, something PostgreSQL can't do across databases.</p>
  
  <p>In db1, I have table1 where I can query for a set of foreign keys keys that I can use to search for records in a table2 in db2, something like:</p>
  
  <pre><code>SELECT * from db2.table2 WHERE db2.table2.primary_key IN (
      SELECT db1.table1.foreign_key FROM db1.table1 WHERE
          db1.table1.primary_key="whatever");
  </code></pre>
  
  <p>What is the best practice for doing this in Postgres? I can't use a temporary tables in db2, and passing in the foreign keys as a parameter in a stored function running in db2 doesn't seem like a good solution. </p>
  
  <p>Note: the keys are all VARCHAR(11)</p>