classCreateRule
final class CreateRule
implements Statement, Relation
uses Snapshot
@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.
$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> $actionspublic Name $namepublic RuleEvent $eventpublic QualifiedName $tablepublic bool $grouped = falsepublic bool|null $instead = nullpublic Scalar|null $where = nullpublic bool $replace = falseMethods§
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
$name | Name | The rule name |
$event | RuleEvent | The rewritten command |
$table | QualifiedName | The table or view |
$actions | list<Statement> | The actions in order; none is NOTHING or an empty list |
$grouped | bool | Whether the actions are written between parentheses |
$instead | bool|null | True for INSTEAD, false for ALSO, null when not written |
$where | Scalar|null | The condition |
$replace | bool | Whether OR REPLACE is written |
Calls 4
- static-call Check::listOf() line 64
- class-const Statement::class() line 64
- static-call Check::input() line 65
- function-call
countline 65
public function deriveStatement(Derivation $derivation): voidResolves the table and derives the condition and the actions.
Parameters
$derivation | Derivation |
Calls 2
- method-call RewriteRules::derive() line 73
- new RewriteRules line 73
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactResolves the table and answers its facts.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 2
- method-call Targets::resolve() line 81
- new Targets line 81
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 2
- method-call RewriteRules::write() line 89
- new RewriteRules line 89
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
- type SqlSemantics\Platform\PostgreSql\Lowering\Table\RewriteRule packages/sql-semantics-postgres/src/Lowering/Table/RewriteRule.php:45
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Command\RewriteRules packages/sql-semantics-postgres/src/Rules/Table/Command/RewriteRules.php:40
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Command\RewriteRules packages/sql-semantics-postgres/src/Rules/Table/Command/RewriteRules.php:67