Trigger Dialog¶
Use the Trigger dialog to create a trigger or modify an existing trigger. A trigger executes a specified function when certain events occur.
The Trigger dialog organizes the development of a trigger through the following dialog tabs: General, Definition, Events, and Code. The SQL tab displays the SQL code generated by dialog selections.
Create Trigger dialog - General tab¶
Use the fields in the General tab to identify the trigger:
Use the
Namefield to add a descriptive name for the trigger. This must be distinct from the name of any other trigger for the same table. The name will be displayed in theBrowsertree control. Note that if multiple triggers of the same kind are defined for the same event, they will be fired in alphabetical order by name.Store notes about the trigger in the
Commentfield.
Click the Definition tab to continue.
Create Trigger dialog - Definition tab¶
Use the fields in the Definition tab to define the trigger:
Move the
Row trigger?switch to theNoposition to disassociate the trigger from firing on each row in a table. The default isYes.Move the
Constraint trigger?switch to theYesposition to specify the trigger is a constraint trigger.If enabled, move the
Deferrable?switch to theYesposition to specify the timing of the constraint trigger is deferrable and can be postponed until the end of the statement. The default isNo.If enabled, move the
Deferred?switch to theYesposition to specify the timing of the constraint trigger is deferred to the end of the statement causing the triggering event. The default isNo.Use the drop-down listbox next to
Trigger Functionto select a trigger function or procedure.Use the
Argumentsfield to provide an optional (comma-separated) list of arguments to the function when the trigger is executed. The arguments are literal string constants.
Create Trigger dialog - Definition tab - Trigger Enable option¶
Trigger enabledfield is available in trigger dialog once the trigger is created. You can select one of the four options available.
Click the Events tab to continue.
Create Trigger dialog - Events tab¶
Use the fields in the Events tab to specify how and when the trigger fires:
Use the drop-down listbox next to the
Firesfields to determine if the trigger firesBEFOREorAFTERa specified event. The default isBEFORE.Select the type of event(s) that will invoke the trigger; to select an event type, move the switch next to the event to the
YESposition. The supported event types areINSERT, UPDATE,DELETE, andTRUNCATE.Use the
Whenfield to provide a boolean condition that will invoke the trigger.If defining a column-specific trigger, use the
Columnsfield to specify the columns or columns that are the target of the trigger.
Click the Code tab to continue.
Create Trigger dialog - Code tab¶
Use the Code field to specify any additional code that will be invoked when the trigger fires.
Click the SQL tab to continue.
Your entries in the Trigger dialog generate a SQL command (see an example below). Use the SQL tab for review; revisit or switch tabs to make any changes to the SQL command.
Example
The following is an example of the sql command generated by user selections in the Trigger dialog:
Create Trigger dialog - SQL tab¶
The example demonstrates creating a trigger named log_update that calls a procedure named log_account_update that logs any updates to the distributors table.
Click the
Infobutton (i) to access online help. View context-sensitive help in theTabbed browser, where a new tab displays the PostgreSQL core documentation.Click the
Savebutton to save work.Click the
Cancelbutton to exit without saving work.Click the
Resetbutton to restore configuration parameters.