Skip to main content

Module create_trigger_stmt

Module create_trigger_stmt 

Source
Expand description

Source parser for CREATE [CONSTRAINT] TRIGGER statements.

Accepts the full PG syntax:

CREATE [ CONSTRAINT ] TRIGGER name { BEFORE | AFTER | INSTEAD OF }
    { event [ OR ... ] }
    ON table_name
    [ NOT DEFERRABLE | DEFERRABLE [ INITIALLY IMMEDIATE | INITIALLY DEFERRED ] ]
    [ REFERENCING { { OLD | NEW } TABLE [ AS ] transition_relation_name } [ ... ] ]
    [ FOR [ EACH ] { ROW | STATEMENT } ]
    [ WHEN ( condition ) ]
    EXECUTE { FUNCTION | PROCEDURE } function_name ( arguments )

Rejects FROM referenced_table_name (the constraint-trigger FROM clause) with ParseError::Structural.

Validates that CONSTRAINT TRIGGER is AFTER + FOR EACH ROW.

§WHEN clause canonicalization

The WHEN expression is canonicalized by wrapping it in a synthetic SELECT <expr> scaffold, deparsing via pg_query::deparse, stripping the SELECT prefix, and feeding the result to NormalizedExpr::from_text after keyword lowercasing. This is the same approach used by crate::parse::normalize_expr::from_pg_node.