A PostgreSQL trigger is a database object that automatically executes a function in response to an event such as insert, update, delete, or truncate. In this section, you will learn about triggers and how to use them effectively.
Neon Postgres - You build apps, we'll run the DB. Neon is serverless Postgres with time-saving features like autoscaling. Start Free
Sponsored
Section 1. Basic PostgreSQL Triggers
- Introduction to PostgreSQL trigger – Give you a brief overview of PostgreSQL triggers, why you should use triggers, and when to use them.
- Create trigger – Show you how to create your first trigger in PostgreSQL.
- Drop trigger– Describe steps for using the
DROP TRIGGER
statement to delete a trigger from a table. - Alter trigger – Guide you on how to use the
ALTER TRIGGER
statement to rename a trigger.
Section 2. INSERT triggers
- BEFORE INSERT triggers – Show you how to create a trigger that is activated automatically before an INSERT event occurs on the associated table.
- AFTER INSERT triggers – Guide you on defining a trigger activated automatically after an INSERT event occurs on the associated table.
Section 3. UPDATE triggers
- BEFORE UPDATE triggers – Define a BEFORE UPDATE trigger that is activated before an update event occurs.
- AFTER UPDATE triggers – Create an AFTER UPDATE trigger fired after an update event occurs.
Section 4. DELETE triggers
- BEFORE DELETE triggers – Define a BEFORE DELETE trigger that fires before a delete event occurs.
- AFTER DELETE triggers – Create an AFTER DELETE trigger fired after a delete event occurs.
Section 5. INSTEAD OF triggers
- INSTEAD OF triggers – Show you how to use the INSTEAD OF trigger to customize the behavior of the INSERT, UPDATE, and DELETE operations on a view.
Section 6. TRUNCATE triggers
- BEFORE TRUNDCATE Trigger – Create a trigger to response before a TRUNCATE event occurs.
Section 7. Enabling & Disabling triggers
- Disable trigger – Show how to disable a trigger or all triggers that belong to a table.
- Enable triggers – Learn how to enable a trigger or all triggers associated with a table.
Section 8. Listing triggers
- Listing triggers – List all triggers associated with a table or all triggers in the current database.
Section 9. Advanced triggers
- Event trigger – Introduce the event trigger that fires when an event related to a DDL statement occurs.
- Conditional trigger – Define a conditional trigger that fires only when a condition is satisfied.