title: CONSTRAINT to check values from a remotely related table (via join etc.)
body: <p>I would like to add a constraint that will check values from related table.</p>
  
  <p>I have 3 tables:</p>
  
  <pre><code>CREATE TABLE somethink_usr_rel (
      user_id BIGINT NOT NULL,
      stomethink_id BIGINT NOT NULL
  );
  
  CREATE TABLE usr (
      id BIGINT NOT NULL,
      role_id BIGINT NOT NULL
  );
  
  CREATE TABLE role (
      id BIGINT NOT NULL,
      type BIGINT NOT NULL
  );
  </code></pre>
  
  <p>(If you want me to put constraint with FK let me know.)</p>
  
  <p>I want to add a constraint to <code>somethink_usr_rel</code> that checks <code>type</code> in <code>role</code> ("two tables away"), e.g.:</p>
  
  <pre><code>ALTER TABLE somethink_usr_rel
      ADD CONSTRAINT CH_sm_usr_type_check 
      CHECK (usr.role.type = 'SOME_ENUM');
  </code></pre>
  
  <p>I tried to do this with <code>JOIN</code>s but didn't succeed. Any idea how to achieve it?</p>