-
@Target({}) @Retention(CLASS) @Documented public @interface Trigger
Annotation, only used in@Function(triggers=...)
, to specify what trigger(s) the function will be called for.Transition tables (
tableOld()
andtableNew()
) appear in PostgreSQL 10. If a trigger is declared withtableOld="oo", tableNew="nn"
, then the trigger function can queryoo
andnn
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 ifevents
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
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description Trigger.Called
called
Denotes if the trigger is fired before, after, or instead of its scope (row or statement)Trigger.Event[]
events
The event(s) that will trigger the call.String
table
The table that this trigger is tied to.
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description String[]
arguments
Arguments to be passed to the trigger function.String[]
columns
A list of columns (only meaningful for an UPDATE trigger).String
comment
A comment to be associated with the trigger.Trigger.Constraint
constraint
Only for a constraint trigger, whether it is deferrable and, if so, initially immediate or deferred.String
from
The name of another table referenced by the constraint.String
fromSchema
The schema containing another table referenced by the constraint.String
name
Name of the trigger.String
schema
The name of the schema containing the table for this trigger.Trigger.Scope
scope
Scope: statement or row.String
tableNew
Name to refer to "after" table of affected rows.String
tableOld
Name to refer to "before" table of affected rows.String
when
A boolean condition limiting when the trigger can be fired.
-
-
-
Element Detail
-
events
Trigger.Event[] events
The event(s) that will trigger the call.
-
-
-
table
String table
The table that this trigger is tied to.
-
-
-
called
Trigger.Called called
Denotes if the trigger is fired before, after, or instead of its scope (row or statement)
-
-
-
arguments
String[] arguments
Arguments to be passed to the trigger function.- Default:
- {}
-
-
-
constraint
Trigger.Constraint constraint
Only 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:
- org.postgresql.pljava.annotation.Trigger.Constraint.NOT_DEFERRABLE
-
-
-
from
String from
The 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:
- ""
-
-
-
name
String name
Name of the trigger. If not set, the name will be generated.- Default:
- ""
-
-
-
schema
String schema
The name of the schema containing the table for this trigger.- Default:
- ""
-
-
-
scope
Trigger.Scope scope
Scope: statement or row.- Default:
- org.postgresql.pljava.annotation.Trigger.Scope.STATEMENT
-
-
-
when
String when
A boolean condition limiting when the trigger can be fired. This text is injected verbatim into the generated SQL, after the keywordWHEN
.- Default:
- ""
-
-
-
columns
String[] columns
A 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 tableOld
Name 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 tableNew
Name 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 comment
A 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:
- ""
-
-