title: How to set up an updatable view with a join in Firebird?
body: <p>I've got three tables, let's call them <code>GRANDPARENT</code>, <code>PARENT</code> and <code>CHILD</code>.  <code>PARENT</code> has a FK column to <code>GRANDPARENT</code>'s PK, and <code>CHILD</code> has a FK column to <code>PARENT</code>'s PK.  So far, so good.</p>
  
  <p>Now I want to set up a view that contains all the information in <code>CHILD</code>, plus the PK from <code>GRANDPARENT</code>.  So:</p>
  
  <pre><code>CREATE VIEW CHILD_VIEW
  (
    ID,
    PARENT_ID,
    OTHER_STUFF,
    GRANDPARENT_ID
  )
  AS
  SELECT 
    C.ID,
    C.PARENT_ID,
    C.OTHER_STUFF,
    C.GRANDPARENT_ID
  FROM CHILD C
  join PARENT P on P.ID = C.PARENT_ID;
  </code></pre>
  
  <p>Not too hard.  But here's the tricky part: I want to be able to <code>INSERT</code> or <code>UPDATE</code> to this view, and have all relevant data get written to the <code>CHILD</code> table, and the <code>GRANDPARENT_ID</code> value, if any, should be ignored.</p>
  
  <p>I've done some Googling around and apparently it should be possible to set up an updatable view like this "by using triggers," but it doesn't explain anywhere what I'm supposed to do with the triggers to achieve this effect.  I think I know more or less how to handle the <code>INSERT</code> case, but what about the <code>UPDATE</code> case?  <code>UPDATE</code> statements have <code>WHERE</code> clauses, and can contain or not contain any arbitrary column(s) in the table.</p>
  
  <p>For example, how do I use a trigger to transform something like <code>update CHILD_VIEW set (blah blah blah) where ID = 5</code> into <code>update CHILD set (blah blah blah excluding GRANDPARENT_ID) where ID = 5</code>?</p>