title: PostgreSQL Trigger on Insert or Update
body: <p>I have two tables. I want to create a trigger on the <code>car</code> table which will insert or delete on the <code>fuel</code> table depending on a certain value.</p>
  
  <p><strong>Car</strong></p>
  
  <pre><code>id - SERIAL
  fuel - BOOLEAN
  </code></pre>
  
  <p><strong>Fuel</strong></p>
  
  <pre><code>car_id -  INTEGER
  </code></pre>
  
  <p>I am not including any row data as the description of the trigger does not need it. </p>
  
  <p>Basically, I want to create a trigger on the <code>Car</code> table that:</p>
  
  <ul>
  <li>Runs on an insert or update. </li>
  <li>Inserts <code>Car.id</code> into <code>Fuel</code> table if <code>Car.fuel is true</code>.</li>
  <li>If <code>Car.fuel is false</code>, the trigger should delete all rows in the <code>Fuel</code> table where <code>Fuel.car_id = Car.id</code>.</li>
  </ul>
  
  <p>How would I do this?</p>
  
  <p>EDIT: To clarify I am using Postgres</p>