final class TriggerReferences
Restricted visibility: declared "@visibility SqlSemantics\Platform\PostgreSql". Code outside that scope must not name this declaration.

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,
): void
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

Returns

list<array{bool, bool, bool}>
Test cases 1
Called from 1
Calls 6
public function selected(object $node): ?ColumnReference
public function reference(object $node, RelationFact $fact): array{bool, bool, bool}|null

Answers 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

$nodeobject
$factRelationFact

Returns

array{bool, bool, bool}|null
Test cases 1
Called from 1
Calls 6

Test cases 3§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 3

Relations§

Instantiated in 2
Method calls 2