@Function(triggers=...)
,
to specify what trigger(s) the function will be called for.
Transition tables (tableOld()
and tableNew()
) appear in
PostgreSQL 10. If a trigger is declared with
tableOld="oo", tableNew="nn"
, then the trigger function can query
oo
and nn
as if they are actual tables with the same
columns as the table responsible for the trigger, and containing the affected
rows before and after the changes. Only an AFTER trigger can have transition
tables. An UPDATE will populate both tables. INSERT will not populate the
old table, and DELETE will not populate the new table. It is an error to
specify either table if events
does not include at least one event
that could populate that table. As long as at least one such event is
included, the table can be specified, and will simply have no rows if the
trigger is invoked for an event that does not populate it.
In an after-statement trigger, the transition tables include all rows affected by the statement. In an after-row trigger, the same is true: after-row triggers are all queued until the statement completes, and then the function will be invoked for each row that was affected, but will see the complete transition tables on each invocation.
- Author:
- Thomas Hallgren
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Whether the trigger is invoked before or after the specified event.static enum
Deferrability (only applies to constraint triggers).static enum
Types of event that can occasion a trigger.static enum
Whether the trigger will occur only once for a statement of interest, or once for each row affected by the statement. -
Required Element Summary
Modifier and TypeRequired ElementDescriptionDenotes if the trigger is fired before, after, or instead of its scope (row or statement)The event(s) that will trigger the call.The table that this trigger is tied to. -
Optional Element Summary
Modifier and TypeOptional ElementDescriptionString[]
Arguments to be passed to the trigger function.String[]
A list of columns (only meaningful for an UPDATE trigger).A comment to be associated with the trigger.Only for a constraint trigger, whether it is deferrable and, if so, initially immediate or deferred.The name of another table referenced by the constraint.The schema containing another table referenced by the constraint.Name of the trigger.The name of the schema containing the table for this trigger.Scope: statement or row.Name to refer to "after" table of affected rows.Name to refer to "before" table of affected rows.A boolean condition limiting when the trigger can be fired.
-
Element Details
-
arguments
String[] argumentsArguments to be passed to the trigger function.- Default:
{}
-
constraint
Trigger.Constraint constraintOnly for a constraint trigger, whether it is deferrable and, if so, initially immediate or deferred. To create a constraint trigger that is not deferrable, this attribute must be explicitly given with the valueNOT_DEFERRABLE
; leaving it to default is not the same. When this attribute is not specified, a normal trigger, not a constraint trigger, is created.A constraint trigger must have
called=AFTER
andscope=ROW
.- Default:
NOT_DEFERRABLE
-
events
Trigger.Event[] eventsThe event(s) that will trigger the call. -
from
String fromThe name of another table referenced by the constraint. This option is used for foreign-key constraints and is not recommended for general use. This can only be specified for constraint triggers. If the name should be schema-qualified, usefromSchema
to specify the schema.- Default:
""
-
fromSchema
String fromSchemaThe schema containing another table referenced by the constraint. This can only be specified for constraint triggers, and only to name the schema for a table named withfrom
.- Default:
""
-
name
String nameName of the trigger. If not set, the name will be generated.- Default:
""
-
schema
String schemaThe name of the schema containing the table for this trigger.- Default:
""
-
table
String tableThe table that this trigger is tied to. -
scope
Trigger.Scope scopeScope: statement or row.- Default:
STATEMENT
-
called
Trigger.Called calledDenotes if the trigger is fired before, after, or instead of its scope (row or statement) -
when
String whenA boolean condition limiting when the trigger can be fired. This text is injected verbatim into the generated SQL, after the keywordWHEN
.- Default:
""
-
columns
String[] columnsA list of columns (only meaningful for an UPDATE trigger). The trigger will only fire for update if at least one of the columns is mentioned as a target of the update command.- Default:
{}
-
tableOld
String tableOldName to refer to "before" table of affected rows. Only usable in an AFTER trigger whoseevents
include UPDATE or DELETE. The trigger function can issue queries as if a table by this name exists and contains all rows affected by the event, in their prior state. (If the trigger is called for an event other than UPDATE or DELETE, the function can still query a table by this name, which will appear to be empty.)- Default:
""
-
tableNew
String tableNewName to refer to "after" table of affected rows. Only usable in an AFTER trigger whoseevents
include UPDATE or INSERT. The trigger function can issue queries as if a table by this name exists and contains all rows affected by the event, in their new state. (If the trigger is called for an event other than UPDATE or INSERT, the function can still query a table by this name, which will appear to be empty.)- Default:
""
-
comment
String commentA comment to be associated with the trigger. If left to default, and the Java function has a doc comment, its first sentence will be used. If an empty string is explicitly given, no comment will be set.- Default:
""
-