title: Execute deferred trigger only once per row in PostgreSQL
body: <p>I have a deferred <code>AFTER UPDATE</code> trigger on a table, set to fire when a certain column is updated. It's an integer type I'm using as a counter.</p>
  
  <p>I'm not 100% certain but it looks like if I increment that particular column 100 times during a transaction, the trigger is queued up and executed 100 times at the end of the transaction.</p>
  
  <p>I would like the trigger to only be scheduled once per row no matter how many times I've incremented that column.</p>
  
  <p>Can I do that somehow?
  Alternatively if triggered triggers must queue up regardless if they are duplicates, can I clear this queue during the first run of the trigger?</p>
  
  <p>Version of Postgres is 9.1. Here's what I got:</p>
  
  <pre><code>CREATE CONSTRAINT TRIGGER counter_change
      AFTER UPDATE OF "Counter" ON "table"
      DEFERRABLE INITIALLY DEFERRED
      FOR EACH ROW
      EXECUTE PROCEDURE counter_change();
  
  CREATE OR REPLACE FUNCTION counter_change()
      RETURNS trigger
      LANGUAGE plpgsql
      AS $$
  DECLARE
  BEGIN
  
  PERFORM some_expensive_procedure(NEW."id");
  
  RETURN NEW;
  
  END;$$;
  </code></pre>