mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-27 11:10:19 -06:00
64 lines
3.7 KiB
ReStructuredText
64 lines
3.7 KiB
ReStructuredText
.. _trigger_dialog:
|
|
|
|
******************
|
|
The 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.
|
|
|
|
.. image:: images/trigger_general.png
|
|
|
|
Use the fields in the *General* tab to identify the trigger:
|
|
|
|
* Use the *Name* field 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 the *pgAdmin* tree 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 *Comment* field.
|
|
|
|
Click the *Definition* tab to continue.
|
|
|
|
.. image:: images/trigger_definition.png
|
|
|
|
Use the fields in the *Definition* tab to define the trigger:
|
|
|
|
* Move the *Row trigger?* switch to the *No* position to disassociate the trigger from firing on each row in a table. The default is *Yes*.
|
|
* Move the *Constraint trigger?* switch to the *Yes* position to specify the trigger is a constraint trigger.
|
|
* If enabled, move the *Deferrable?* switch to the *Yes* position to specify the timing of the constraint trigger is deferrable and can be postponed until the end of the statement. The default is *No*.
|
|
* If enabled, move the *Deferred?* switch to the *Yes* position to specify the timing of the constraint trigger is deferred to the end of the statement causing the triggering event. The default is *No*.
|
|
* Use the drop-down listbox next to *Trigger Function* to select a trigger function or procedure.
|
|
* Use the *Arguments* field to provide an optional (comma-separated) list of arguments to the function when the trigger is executed. The arguments are literal string constants.
|
|
|
|
Click the *Events* tab to continue.
|
|
|
|
.. image:: images/trigger_events.png
|
|
|
|
Use the fields in the *Events* tab to specify how and when the trigger fires:
|
|
|
|
* Use the drop-down listbox next to the *Fires* fields to determine if the trigger fires *BEFORE* or *AFTER* a specified event. The default is *BEFORE*.
|
|
* 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 *YES* position. The supported event types are *INSERT*, *UPDATE*, *DELETE*, and *TRUNCATE*.
|
|
* Use the *When* field to provide a boolean condition that will invoke the trigger.
|
|
* If defining a column-specific trigger, use the *Columns* field to specify the columns or columns that are the target of the trigger.
|
|
|
|
Click the *Code* tab to continue.
|
|
|
|
.. image:: images/trigger_code.png
|
|
|
|
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:
|
|
|
|
.. image:: images/trigger_sql.png
|
|
|
|
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 *Info* button (i) to access online help. View context-sensitive help in the *Tabbed browser*, where a new tab displays the PostgreSQL core documentation.
|
|
* Click the *Save* button to save work.
|
|
* Click the *Cancel* button to exit without saving work.
|
|
* Click the *Reset* button to restore configuration parameters. |