Overview - NEW and OLD record access
What is it?
In PostgreSQL triggers, NEW and OLD are special records that let you see the data before and after a change. OLD holds the row data before an update or delete, while NEW holds the row data after an insert or update. These allow you to compare or modify data during trigger execution. They are essential for writing triggers that react to data changes.
Why it matters
Without NEW and OLD, you couldn't track or react to changes in your database rows automatically. This would make it hard to enforce rules, audit changes, or maintain data integrity. They let the database itself watch and respond to data changes, saving time and preventing errors.
Where it fits
You should know basic SQL commands like INSERT, UPDATE, and DELETE before learning about NEW and OLD. After this, you can learn how to write triggers and functions that automate database tasks or enforce complex rules.