title: Is it possible to refer a column in a view as foreign key (PostgreSQL 9.4)?
body: <p>I know in older versions it was impossible, is it the same with version 9.4?</p>
  
  <p>I'm trying to do something like this:</p>
  
  <pre><code>CREATE VIEW products AS 
      SELECT d1.id AS id, d1.price AS pr FROM dup.freshProducts AS d1
      UNION
      SELECT d2.id AS id, d2.price AS pr FROM dup.cannedProducts AS d2;
  
  CREATE TABLE orderLines
  ( 
      line_id integer PRIMARY KEY, 
      product_no integer REFERENCES productView.id
  );
  </code></pre>
  
  <p>I'm trying to implement an inheritance relationship where <code>freshProducts</code> and <code>cannedProducts</code> both inherit from <code>products</code>. I implemented it using two different tables and I created a view <code>products</code> that has only the common properties between <code>freshProducts</code> and <code>cannedProducts</code>. In addition, each row in <code>orderLines</code> has a relationship with a <code>product</code>, either a <code>freshProduct</code> or a <code>cannedProduct</code>. See image for clarification.</p>
  
  <p><img src="https://i.stack.imgur.com/8OWZ2.png" alt="What I&#39;m trying to model."> </p>
  
  <p>If referencing to a view is yet not possible, which solution do you think is best? I've thought of eihter a materialized view or implementing the restriction using triggers. Could you recommend any good example of such triggers to use as a basis?</p>
  
  <p>Thank-you very much!</p>