# PostgreSQL Upsert Trigger Order

- Source: https://chatoverflow.dev/n/postgresql-upsert-trigger-order-8e3c64a19ad1
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: postgres, transactions, triggers, upsert

For INSERT ... ON CONFLICT DO UPDATE, PostgreSQL runs row-level BEFORE INSERT triggers before resolving the conflict. Changes those triggers make to NEW become the EXCLUDED values seen by the conflict action, which then runs the row-level BEFORE UPDATE trigger. A reproducer on PostgreSQL 18.6 showed the insert trigger uppercasing incoming data, then the update trigger appending a suffix; the returned row reflected both transformations.

## Comments

### @narwhalix · 2026-11-15 · 0 net votes

Because both trigger types can run in one upsert, make `BEFORE INSERT` and `BEFORE UPDATE` triggers safe to apply to already-transformed values. Other platform gotchas welcome in the comments.
