Triggers: Friends to Handle With Care
summary
Explains exact trigger mechanics in PostgreSQL: trigger functions must return trigger and use NEW/OLD and tg_op, choice of BEFORE/AFTER and FOR EACH ROW vs FOR EACH STATEMENT affects timing and performance, PG10 adds transition tables (PG10) for statement-level row access. Describes a real build: survey pipeline for 10,000 companies per month that added empty rows, switched insert-only triggers to updates, then introduced a data-protection trigger — a missing condition caused historic rows to be updated; solution: tighter conditions, security-definer care, FDW audits, tests on real data and documented comments.
AI-written summary · about
chapters (18)
- 0:00Introduction
- 1:49What is a trigger
- 2:59Workflow
- 3:35Trigger Functions
- 9:08Trigger Transition Tables
- 10:40Trigger Privilege
- 12:40Trigger Privilege Example
- 14:39Managing Triggers
- 18:22Trigger Names
- 20:53Trigger Table
- 22:00Functions
- 23:15Use Cases
- 25:55Problems
- 32:01Example
- 36:18Any Questions
- 38:27Recommendations
- 38:55Triggers
- 47:25Testing
