title: Foreign Key referencing inherited table
body: <p>I have the following tables:</p>
  
  <pre><code>CREATE TABLE mail (
      id serial,
      parent_mail_id integer,
      ...
  
      PRIMARY KEY (id),
      FOREIGN KEY (parent_mail_id) REFERENCES mail(id),
      ...
  );
  
  CREATE TABLE incoming (
      from_contact_id integer NOT NULL REFERENCES contact(id),
      ...
      PRIMARY KEY (id),
      ---&gt; FOREIGN KEY (parent_mail_id) REFERENCES mail(id), &lt;---
      ...
  ) INHERITS(mail);
  
  CREATE TABLE outgoing (
      from_user_id integer NOT NULL REFERENCES "user"(id),
      ...  
      PRIMARY KEY (id),
      --&gt; FOREIGN KEY (parent_mail_id) REFERENCES mail(id), &lt;--
      ...
  ) INHERITS(mail);
  </code></pre>
  
  <p><code>incoming</code> and <code>outgoing</code> inherit from <code>mail</code> and define their foreign keys (and primary keys) again, as they are not automatically inherited.</p>
  
  <p>The problem is:</p>
  
  <p>If I'd insert an <code>incoming</code> mail, it is not possible to reference it from the <code>outgoing</code> table as the foreign key only works with the super table (<code>mails</code>).</p>
  
  <p><strong>Is there a workaround for that?</strong></p>