Database Reference
In-Depth Information
Creating the trigger
The simplified syntax for creating a user-defined TRIGGER statement is given as fol-
lows:
CREATE TRIGGER name
{ BEFORE | AFTER | INSTEAD OF } { event [
OR ... ] }
ON table_name
[ FOR [ EACH ] { ROW | STATEMENT } ]
EXECUTE PROCEDURE function_name ( arguments
)
In the preceding code the event is one of INSERT , UPDATE , DELETE , or TRUNCATE .
There are a few more options which we will come back to in a later section.
The "arguments" seemingly passed to the trigger function in the trigger definition are
not used as arguments when calling the trigger. Instead, they are available to trig-
ger function as a text array ( text[] ) in variable TG_ARGV (length of this array is in
TG_NARGS ). Let's start slowly investigating how triggers and trigger functions work.
First, we will use a simple trigger example and move to more complex examples
step-by-step.
Search WWH ::




Custom Search