title: Postgresql 13 - fire trigger once for group records
body: <p>I have table:</p>
  <pre><code>| id |depth| depth_ex| b_id|
  |----|-----|---------|-----|
  |  1 |   0 |   0.00  |  1  |
  |  2 |   1 |   1.00  |  1  |
  |  3 |   2 |   3.00  |  1  |
  | 15 |   3 |   6.00  |  1  |
  |  6 |  35 |  41.00  |  1  |
  | 12 | 100 | 141.00  |  1  |
  |  9 |   0 |   0.00  |  2  |
  | 10 |  20 |  20.00  |  2  |
  | 11 |  40 |  60.00  |  2  |
  </code></pre>
  <p>For this table, i created TRIGGER:</p>
  <pre><code>CREATE OR REPLACE FUNCTION depth_ex() RETURNS trigger
     LANGUAGE plpgsql AS
  $$
  BEGIN
      RAISE NOTICE '!!!!!!!!!!!!!!'; 
  
      UPDATE a
        SET depth_ex = sub.new_depth
      FROM (
          SELECT
               id,
              SUM(depth) OVER (ORDER BY depth ASC) AS new_depth
          FROM
              a
          WHERE b_id = NEW.b_id
      ) sub
      WHERE a.id = sub.id;
   
      RETURN NULL;
  END;
  $$;
   
  CREATE CONSTRAINT TRIGGER depth_ex_trig
     AFTER INSERT OR UPDATE OF depth ON a
     DEFERRABLE INITIALLY DEFERRED
     FOR EACH ROW EXECUTE PROCEDURE depth_ex();
  </code></pre>
  <p>After:</p>
  <pre><code>BEGIN;
  UPDATE a SET depth = 6 where id = 2;
  UPDATE a SET depth = 10 where id = 3;
  UPDATE a SET depth = 15 where id = 15;
  COMMIT;
  </code></pre>
  <p>I expected to see !!!!!!!! only one, but i saw three times.</p>
  <pre><code>NOTICE:  !!!!!!!!
  NOTICE:  !!!!!!!!
  NOTICE:  !!!!!!!!
  COMMIT
  
  Query returned successfully in 31 msec.
  </code></pre>
  <p>How to rewrite procedure or trigger to see NOTICE:  !!!!!!!! only once, or fire trigger for group of record one ( with the same b_id) ?</p>
  <p>Regards</p>