RANIARANIA Academy

Triggers & Event-Driven Logic

Learn to automate data integrity and auditing in PostgreSQL with triggers. You will write trigger functions in PL/pgSQL, choose BEFORE/AFTER and ROW/STATEMENT timing correctly, use NEW and OLD to validate and transform data, and build a reusable audit-log trigger — while avoiding recursion, ordering and performance pitfalls.

Watch the free preview

What a trigger is and how to write a trigger function — free to watch, no account needed.

PostgreSQL ADVANCED · 150 min · Certificate on completion · 3 CPD points

What you'll learn

  • Automate data integrity and auditing with PostgreSQL triggers
  • Write PL/pgSQL trigger functions that use NEW and OLD correctly
  • Choose BEFORE/AFTER and ROW/STATEMENT timing for each task
  • Build a reusable audit-log trigger that records every change
  • Diagnose and avoid trigger recursion, ordering and performance pitfalls

Syllabus

Trigger Fundamentals
What a trigger is and how to write a trigger functionFree preview15 min
BEFORE and AFTER, and the NEW and OLD records15 min
Row versus Statement, and Enforcing Rules
ROW-level versus STATEMENT-level triggers15 min
Enforcing rules and transforming data with NEW and OLD15 min
Auditing and Cascading Effects
Building an audit-log trigger15 min
Cascading effects — triggers that change other tables15 min
Pitfalls and Performance
Trigger pitfalls — recursion, ordering and surprises15 min
Performance and when not to use a trigger15 min
Lab — 10 Exercises & Solutions
Exercises 1–515 min
Exercises 6–1015 min