Create Trigger

Creates a new trigger.


CREATE TRIGGER name { BEFORE | AFTER } { event [ OR event ... ] }
       ON table FOR EACH { ROW | STATEMENT }
       EXECUTE PROCEDURE function ( arguments )



The name of the new trigger.


The name of the table with which the trigger will be associated.


The event with which you wish to associate the trigger, that causes the trigger to fire. Valid events are: INSERT, DELETE, and UPDATE. A trigger may be associated with more than one event.


The name of the function you wish to link to the new trigger. When the trigger fires, the function is invoked. The function must return a variable of type opaque; the opaque type is used only by internal functions and such functions cannot be invoked directly from SQL.


The arguments to pass to the function when the trigger is called.



The message returned when a trigger is successfully created.


Use the CREATE TRIGGER command to add a trigger to a database. When a trigger is added to the database, it is associated with the table specified in the ON clause. When the specified event “fires” the trigger, the function you specified will be executed.



A trigger may only be created on a table by the table’s owner, or by a superuser.

When you create a trigger, you must specify whether it is to be fired before or after the event is attempted (or completed). If the trigger ...

Get Practical PostgreSQL now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.