classTriggerReferences
final class TriggerReferences
Reports the references to OLD and NEW that a trigger's WHEN condition may not make.
Rule: PG-TRIGGER-WHEN-001. The server parses the condition with OLD and NEW in scope for every trigger, then checks each column reference of the result in order (CreateTriggerFiringOn, trigger.c): a reference to OLD or NEW in a statement trigger is an error; in a row trigger, a reference to OLD when INSERT is one of the events, a reference to NEW when DELETE is one of the events, and, in a BEFORE trigger, a reference to a system column of NEW, to a generated column of NEW, or to the whole row of NEW when the table has a generated column are errors ("BEFORE trigger's WHEN condition
- cannot reference NEW generated columns", with a detail naming the column
or the whole-row reference). The first broken rule, in the order the references are written, is reported. A reference counts when it is known to resolve: old.*, new.*, a whole-row old or new that is not a column name, old.c or new.c for a column or system column c of a table whose shape is complete, and a field selection (new).c of such a column, which the server reads as the column. Terminates: one pass over the finite value graph of the condition. Source: https://www.postgresql.org/docs/17/sql-createtrigger.html, https://www.postgresql.org/docs/16/ddl-generated-columns.html, https://github.com/postgres/postgres/blob/REL_17_2/src/backend/commands/trigger.c. Status: Implemented.
Methods§
public function check(
Derivation $derivation,
Scalar $when,
RelationFact $fact,
bool $row,
list<TriggerEvent> $events,
bool $before,
): voidReports the first reference of the condition that the trigger may not make.
Parameters
$derivation | Derivation | |
$when | Scalar | |
$fact | RelationFact | |
$row | bool | |
$events | list<TriggerEvent> | The events the trigger fires on |
$before | bool | Whether the trigger fires BEFORE the event |
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Triggers::derive() packages/sql-semantics-postgres/src/Rules/Table/Command/Triggers.php:75
- method-call SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Triggers::deriveConstraint() packages/sql-semantics-postgres/src/Rules/Table/Command/Triggers.php:94
Calls 12
- function-call
array_mapline 57 - method-call TriggerReferences::references() line 58
- class-const DefinitionRule::StatementTriggerColumns() line 60
- function-call
in_arrayline 61 - class-const TriggerEventKind::Insert() line 61
- class-const DefinitionRule::InsertTriggerOld() line 61
- class-const TriggerEventKind::Delete() line 62
- class-const DefinitionRule::DeleteTriggerNew() line 62
- class-const DefinitionRule::BeforeTriggerSystemColumn() line 63
- class-const DefinitionRule::BeforeTriggerGeneratedColumn() line 64
- method-call Derivation::report() line 68
- new DefinitionProblem line 68
public function references(Scalar $when, RelationFact $fact): list<array{bool, bool, bool}>Answers, in written order, whether each reference of the condition to OLD or NEW is to OLD (else NEW), to a system column, and to a generated column or a whole row holding one.
The value graph lists the nodes of the condition depth first from the last member, so its reverse lists the references in written order; a field selection of a whole-row reference counts once, as the column it selects.
Parameters
$when | Scalar | |
$fact | RelationFact |
Returns
list<array{bool, bool, bool}>Test cases 1
Called from 1
Calls 6
- function-call
array_reverseline 87 - method-call ValueGraph::objects() line 87
- new ValueGraph line 87
- method-call TriggerReferences::selected() line 90
- function-call
in_arrayline 100 - method-call TriggerReferences::reference() line 100
public function selected(object $node): ?ColumnReferenceAnswers the column reference a field selection of a whole-row OLD or NEW stands for, (new).c as new.c, or null for any other node.
Parameters
$node | object |
Returns
Test cases 1
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Table\Command\TriggerReferences::references() packages/sql-semantics-postgres/src/Rules/Table/Command/TriggerReferences.php:90
- method-call SqlSemantics\Platform\PostgreSql\Rules\Table\Command\TriggerReferences::references() packages/sql-semantics-postgres/src/Rules/Table/Command/TriggerReferences.php:100
Calls 3
- function-call
countline 121 - function-call
in_arrayline 121 - new ColumnReference line 125
public function reference(object $node, RelationFact $fact): array{bool, bool, bool}|nullAnswers whether a node of the condition refers to OLD (else NEW), to a system column, and to a generated column or a whole row holding one, or null when it refers to neither or may not resolve.
Parameters
$node | object | |
$fact | RelationFact |
Returns
array{bool, bool, bool}|nullTest cases 1
Called from 1
Test cases 3§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Relations§
Instantiated in 2
- new SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Triggers::derive() packages/sql-semantics-postgres/src/Rules/Table/Command/Triggers.php:75
- new SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Triggers::deriveConstraint() packages/sql-semantics-postgres/src/Rules/Table/Command/Triggers.php:94
Method calls 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Triggers::derive() packages/sql-semantics-postgres/src/Rules/Table/Command/Triggers.php:75
- method-call SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Triggers::deriveConstraint() packages/sql-semantics-postgres/src/Rules/Table/Command/Triggers.php:94