| From: | Paul A Jungwirth <pj(at)illuminatedcomputing(dot)com> |
|---|---|
| To: | jian he <jian(dot)universality(at)gmail(dot)com> |
| Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: UPDATE/DELETE FOR PORTION OF fire FOR EACH STATEMENT more than once |
| Date: | 2026-05-03 15:57:46 |
| Message-ID: | CA+renyXqdJ4iOWiXEn+9fMkdD8RUrmnnzTeRe+08CuAZLqvz_g@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Sat, May 2, 2026 at 9:49 PM jian he <jian(dot)universality(at)gmail(dot)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(at)illuminatedcomputing(dot)com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | SATYANARAYANA NARLAPURAM | 2026-05-03 18:04:59 | Re: Infinite Autovacuum loop caused by failing virtual generated column expression |
| Previous Message | Andy Fan | 2026-05-03 14:41:27 | Re: Make printtup a bit faster |