classCreateTrigger
final class CreateTrigger
implements SchemaElement, Relation
uses Snapshot
@visibility public.A request to create a trigger.
Mirrors PostgreSQL's CreateTrigStmt without isconstraint (replace, trigname, relation, funcname, args, row, timing, events, whenClause, transitionRels). Rule PG-TRIGGER-001: the table is resolved and is the relation fact of the statement; the WHEN condition of a row trigger sees the table's columns as OLD and NEW, and that of a statement trigger sees no column. FOR [ EACH ] — EACH is optional — and PROCEDURE for FUNCTION are not kept. Source: https://www.postgresql.org/docs/17/sql-createtrigger.html.
$statement = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE OR REPLACE TRIGGER g BEFORE UPDATE OR DELETE ON t FOR ROW WHEN (old.a <> new.a) EXECUTE PROCEDURE f()');
$statement->toString() // => 'CREATE OR REPLACE TRIGGER g BEFORE UPDATE OR DELETE ON t FOR EACH ROW WHEN (old.a <> new.a) EXECUTE FUNCTION f()'Properties§
public non-empty-list<TriggerEvent> $eventspublic list<TriggerArgument> $argumentspublic list<TriggerTransition> $transitionspublic Name $namepublic TriggerTiming $timingpublic QualifiedName $tablepublic DottedName $functionpublic bool|null $row = nullpublic Scalar|null $when = nullpublic bool $replace = falseMethods§
public function __construct(
public Name $name,
public TriggerTiming $timing,
list<TriggerEvent> $events,
public QualifiedName $table,
public DottedName $function,
list<TriggerArgument> $arguments = [],
public bool|null $row = null,
list<TriggerTransition> $transitions = [],
public Scalar|null $when = null,
public bool $replace = false,
)Parameters
$name | Name | The trigger name |
$timing | TriggerTiming | When the trigger fires |
$events | list<TriggerEvent> | The events |
$table | QualifiedName | The table, view or foreign table |
$function | DottedName | The trigger function |
$arguments | list<TriggerArgument> | The arguments |
$row | bool|null | True for FOR EACH ROW, false for FOR EACH STATEMENT, null when not written (statement level) |
$transitions | list<TriggerTransition> | The REFERENCING items |
$when | Scalar|null | The WHEN condition |
$replace | bool | Whether OR REPLACE is written |
Calls 4
- static-call Check::listOf() line 80
- class-const TriggerEvent::class() line 80
- class-const TriggerArgument::class() line 81
- class-const TriggerTransition::class() line 82
public function deriveStatement(Derivation $derivation): voidResolves the table and derives the condition.
Parameters
$derivation | Derivation |
Calls 2
- method-call Triggers::derive() line 98
- new Triggers line 98
public function deriveElement(Derivation $derivation, Name $schema): voidDerives the statement inside CREATE SCHEMA: an unqualified table is in that schema.
Parameters
$derivation | Derivation | |
$schema | Name |
Calls 2
- method-call Triggers::derive() line 106
- new Triggers line 106
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactResolves the table as written and answers its facts.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 2
- method-call Targets::resolve() line 114
- new Targets line 114
Test cases 5§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.