In the object hierarchy under every table are Triggers. Triggers can be added by selecting CREATE TRIGGER from the Triggers context menu. Once a trigger has been created, it can be commented on and dropped. This section describes how to create, comment on, and drop a trigger with Administrator.
In this example, you will create a trigger called logger.
A trigger is an object under a table, so to create a trigger, first expand the table under which you wish to create the trigger (click the [O-] beside the table name). In this example, choose the table named invoices in the schema web_store_schema.
Right-click on Triggers and choose CREATE TRIGGER. The CREATE TRIGGER dialog box appears.
In the Name For The New Trigger field, type: logger
The Procedure combo-box allows the selection of the PostgreSQL function that will be activated when the trigger fires, which is usually referred to as the "trigger function". This function must have been previously created and registered with the database (refer to the PostgreSQL 7.3 Programmer's Guide for information on how to create trigger functions). For this example, choose invoices_logger() as the procedure. (These steps assume that you have created a trigger function called invoices_logger().) An optional entry box is provided in case the trigger function requires arguments.
Two sets of buttons allow for the specification of when and under what circumstances a trigger should fire. The first set of buttons define When To Fire the trigger, before or after the event that caused the trigger to fire. For this example, choose After. The On Events set of check boxes define which events fire the triggers, which can be any combination of INSERT, DELETE, or UPDATE operations. For this example, select all three events.
Click OK to create the trigger.
Note that the trigger logger has been added under the Triggers node in the Tree View.
Administrator also enables you to perform the following operations on existing triggers:
PostgreSQL allows commenting on trigger, which makes them easier to identify. To comment on a trigger, right-click on it and select COMMENT. A dialog asks for the comment. If there is already a comment on the trigger, this comment is displayed. Type the new comment in the edit box and click OK to save the new comment.
To drop a trigger, right-click on it and select either DROP RESTRICT or DROP CASCADE. DROP RESTRICT will not drop the trigger if there are any dependent objects. DROP CASCADE automatically drops the trigger and all objects that depend on it.
If Preferences => Ask For Confirmations is enabled, you are asked to confirm that you want the trigger dropped (and all the dependent objects in case of a DROP CASCADE); if it is disabled, the trigger is dropped immediately (along with its dependent objects if DROP CASCADE was selected). This action cannot be undone.
In PostgreSQL 7.3 backends, triggers can be renamed. To rename a trigger, right-click on it and select RENAME TRIGGER. Type in the new name in the dialog that appears and click OK.
![]() | Note |
|---|---|
SELECT TRIGGER commands are used to implement views in PostgreSQL. The CREATE VIEW command is the appropriate method for creating views and you must not create triggers on SELECT directly. For this reason, an option to fire a trigger on SELECT has not been provided, despite the fact that the SQL syntax allows it. Refer to the PostgreSQL 7.3 Reference Manual for more information on views and triggers. |