Skip to content
masterclass Buddy

PostgreSQL · Command

CREATE TRIGGER

CREATE TRIGGER defines a trigger that calls a user-supplied function when selected operations occur on a table, view, or foreign table. It supports timing, event, row or statement scope, and optional conditions.

Last updated

Syntax

CREATE [ OR REPLACE ] [ CONSTRAINT ] TRIGGER name { BEFORE | AFTER | INSTEAD OF } { event [ OR ... ] } ON table_name [ FROM referenced_table_name ] [ NOT DEFERRABLE | [ DEFERRABLE ] [ INITIALLY IMMEDIATE | INITIALLY DEFERRED ] ] [ REFERENCING { { OLD | NEW } TABLE [ AS ] transition_relation_name } [ ... ] ] [ FOR [ EACH ] { ROW | STATEMENT } ] [ WHEN ( condition ) ] EXECUTE { FUNCTION | PROCEDURE } function_name ( arguments )

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • DROP TRIGGER
  • CREATE FUNCTION
  • constraint trigger
  • transition tables
  • BEFORE trigger
  • AFTER trigger
  • INSTEAD OF trigger

Source: CREATE TRIGGER. Checked 2026-11-03.