title: postgres INSERT trigger fires even with ON CONFLICT DO NOTHING
body: <p>In a couple of SO answers (<a href="https://stackoverflow.com/a/41435016/5578790">1</a>, <a href="https://stackoverflow.com/a/40731729/5578790">2</a>), it's suggested that <code>INSERT</code> triggers shouldn't fire if there's a conflict and <code>ON CONFLICT DO NOTHING</code> is in the triggering statement. Perhaps I've misunderstood, but it does not seem to be true in my experiments.</p>
  
  <p>Here's my SQL, run on Postgres 9.6.</p>
  
  <pre><code>CREATE TABLE t (
          n text PRIMARY KEY
  );
  
  CREATE FUNCTION def() RETURNS trigger AS $$
  BEGIN
          RAISE NOTICE 'Called def()';
          RETURN NEW;
  END;
  $$ LANGUAGE plpgsql;
  
  CREATE TRIGGER deftrig BEFORE INSERT ON t FOR EACH ROW EXECUTE PROCEDURE def();
  </code></pre>
  
  <p>If I then run a couple of inserts:</p>
  
  <pre><code>testdb=&gt; insert into t (n) values ('dummy') on conflict do nothing;
  NOTICE:  Called def()
  INSERT 0 1
  testdb=&gt; insert into t (n) values ('dummy') on conflict do nothing;
  NOTICE:  Called def()
  INSERT 0 0
  </code></pre>
  
  <p>I would have expected to see <code>Called def()</code> the first time, but not the next.</p>
  
  <p>What am I getting wrong?</p>