Creating Custom Triggers

There is a certain degree of overlap between stored procedures (that is, functions) and triggers. Both operate as predefined code created with the CREATE FUNCTION statement. However, triggers are most often used as an automated response to some table-related event, not as an action directly called by a client application.

Triggers bind these functions to DELETE, UPDATE, or INSERT table events using the CREATE TRIGGER command. The client application has no direct knowledge of a trigger’s existence; it simply performs the requested action, which results in the server firing the appropriate trigger event.

Triggers are used for performing actions that pertain to the same table that is being accessed. Often they are used ...

Get PostgreSQL Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.