Re: UPDATE/DELETE FOR PORTION OF fire FOR EACH STATEMENT more than once - Mailing list pgsql-hackers

From Paul A Jungwirth
Subject Re: UPDATE/DELETE FOR PORTION OF fire FOR EACH STATEMENT more than once
Date
Msg-id CA+renyXqdJ4iOWiXEn+9fMkdD8RUrmnnzTeRe+08CuAZLqvz_g@mail.gmail.com
Whole thread
In response to UPDATE/DELETE FOR PORTION OF fire FOR EACH STATEMENT more than once  (jian he <jian.universality@gmail.com>)
List pgsql-hackers
On Sat, May 2, 2026 at 9:49 PM jian he <jian.universality@gmail.com> wrote:
> drop table if exists ts;
> create table ts(a int4range, b int);
> insert into ts values('[1,10)', 2), ('[1,10)', 3);
> CREATE TRIGGER ts_trig1
>   BEFORE INSERT OR UPDATE OR DELETE ON ts
>   FOR EACH STATEMENT EXECUTE PROCEDURE trigger_info();
>
> update ts for portion of a from 2 to 4 set b = 12;
>
> The above UPDATE statement is triggering the BEFORE FOR EACH STATEMENT
> action four times.
> This appears to contradict the documentation mentioned below.
> Am I missing something?

In fact it fires once for the update, and four times for the inserts.
This behavior is correct and intended. The standard says that the
inserts for temporal leftovers are "statements", so we decided to fire
statement triggers on them. We talked about this a lot at the last
PGConf and in some emails afterwards. Here is a mailing list thread
with lots of details:
https://www.postgresql.org/message-id/ec498c3d-5f2b-48ec-b989-5561c8aa2024%40illuminatedcomputing.com

Yours,

--
Paul              ~{:-)
pj@illuminatedcomputing.com



pgsql-hackers by date:

Previous
From: Andy Fan
Date:
Subject: Re: Make printtup a bit faster
Next
From: SATYANARAYANA NARLAPURAM
Date:
Subject: Re: Infinite Autovacuum loop caused by failing virtual generated column expression