title: Map column value to table name and join
body: <p>I have a composite type that looks like</p>
  
  <pre><code>CREATE TYPE member AS (
      id BIGINT,
      type CHAR(1)
  );
  </code></pre>
  
  <p>I have a table that relies on this <code>member</code> type with an array.</p>
  
  <pre><code>CREATE TABLE relation (
      id BIGINT PRIMARY KEY,
      members member[]
  );
  </code></pre>
  
  <p>I have three other tables each with a different schema (but having common <code>id</code> field)</p>
  
  <pre><code>CREATE TABLE table_x (
      id BIGINT PRIMARY KEY,
      some_text TEXT
  );
  
  CREATE TABLE table_y (
      id BIGINT PRIMARY KEY,
      some_int INT
  );
  
  CREATE TABLE table_z (
      id BIGINT PRIMARY KEY,
      some_date TIMESTAMP
  );
  </code></pre>
  
  <p><code>type</code> field in <code>member</code> type is just one character to find out table that specific member belongs to. A row in <code>relation</code> table can have a mix of different <code>type</code>s.</p>
  
  <p>I have a scenario which requires returning <code>relation</code> ids with at least one <code>member</code> fulfilling a certain condition based on it's type (let's say for <code>x</code> => <code>some_text</code> is not empty or <code>y</code> => <code>some_int</code> is greater than 10 or <code>z</code> => <code>some_date</code> is a week is from now).</p>
  
  <p>I can implement this scenario on the application side by making multiple requests to the database:</p>
  
  <ul>
  <li>unnest <code>relation</code> table</li>
  <li>collect <code>member</code> data per <code>relation</code></li>
  <li>make new requests to find out <code>relation</code>s</li>
  </ul>
  
  <p>I am wondering if there is a way to map column values to table names and join them.</p>