final class CreateTrigger
    implements SchemaElement, Relation
    uses Snapshot
Public API: explicitly declared with @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.

Resolving a row trigger conditiondoctest
$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> $events
public list<TriggerArgument> $arguments
public list<TriggerTransition> $transitions
public Name $name
public TriggerTiming $timing
public QualifiedName $table
public DottedName $function
public bool|null $row = null
public Scalar|null $when = null
public bool $replace = false

Methods§

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

$nameNameThe trigger name
$timingTriggerTimingWhen the trigger fires
$eventslist<TriggerEvent>The events
$tableQualifiedNameThe table, view or foreign table
$functionDottedNameThe trigger function
$argumentslist<TriggerArgument>The arguments
$rowbool|nullTrue for FOR EACH ROW, false for FOR EACH STATEMENT, null when not written (statement level)
$transitionslist<TriggerTransition>The REFERENCING items
$whenScalar|nullThe WHEN condition
$replaceboolWhether OR REPLACE is written
Calls 4
public function createdSchema(): ?Name

Answers the schema written on the table.

Returns

public function deriveStatement(Derivation $derivation): void

Resolves the table and derives the condition.

Parameters

$derivationDerivation
Calls 2
public function deriveElement(Derivation $derivation, Name $schema): void

Derives the statement inside CREATE SCHEMA: an unqualified table is in that schema.

Parameters

$derivationDerivation
$schemaName
Calls 2
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFact

Resolves the table as written and answers its facts.

Parameters

$derivationDerivation
$environmentEnvironment
Calls 2
public function render(Output $out): void

Writes the statement.

Parameters

$outOutput
Calls 2

Test cases 5§

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

Dedicated tests 3
Other tests reaching this symbol 2

Relations§

Instantiated in 1
Constant reads 1
Type declarations 2