final class CreateRule
    implements Statement, Relation
    uses Snapshot
Public API: explicitly declared with @visibility public.

A request to create a rewrite rule: commands that replace or accompany a command on a table or view.

Mirrors PostgreSQL's RuleStmt (relation, rulename, whereClause, event, instead, actions, replace). Rule PG-REWRITE-RULE-001: the table is resolved and is the relation fact of the statement; the WHERE condition sees OLD and NEW (PG-OLD-NEW-001); the actions see OLD and NEW with a qualifier only. NOTHING is no action without parentheses; empty statements between semicolons are not kept. Source: https://www.postgresql.org/docs/17/sql-createrule.html.

Reading a ruledoctest
$statement = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE OR REPLACE RULE r AS ON UPDATE TO t WHERE old.a <> new.a DO ALSO (INSERT INTO log VALUES (old.a); DELETE FROM log WHERE a = new.a)');
    [count($statement->statement->actions), $statement->toString()] // => [2, 'CREATE OR REPLACE RULE r AS ON UPDATE TO t WHERE old.a <> new.a DO ALSO (INSERT INTO log VALUES (old.a); DELETE FROM log WHERE a = new.a)']

Properties§

public list<Statement> $actions
public Name $name
public RuleEvent $event
public QualifiedName $table
public bool $grouped = false
public bool|null $instead = null
public Scalar|null $where = null
public bool $replace = false

Methods§

public function __construct(
    public Name $name,
    public RuleEvent $event,
    public QualifiedName $table,
    list<Statement> $actions = [],
    public bool $grouped = false,
    public bool|null $instead = null,
    public Scalar|null $where = null,
    public bool $replace = false,
)

Parameters

$nameNameThe rule name
$eventRuleEventThe rewritten command
$tableQualifiedNameThe table or view
$actionslist<Statement>The actions in order; none is NOTHING or an empty list
$groupedboolWhether the actions are written between parentheses
$insteadbool|nullTrue for INSTEAD, false for ALSO, null when not written
$whereScalar|nullThe condition
$replaceboolWhether OR REPLACE is written
Calls 4
public function deriveStatement(Derivation $derivation): void

Resolves the table and derives the condition and the actions.

Parameters

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

Resolves the table and answers its facts.

Parameters

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

Writes the statement.

Parameters

$outOutput
Calls 2

Test cases 2§

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

Dedicated tests 2

Relations§

Instantiated in 1
Type checks 1
Type declarations 3