classCreatePolicy
final class CreatePolicy
implements Statement, Relation
uses Snapshot
Public API: explicitly declared with
@visibility public.A request to create a row security policy.
Mirrors PostgreSQL's CreatePolicyStmt (policy_name, table, cmd_name, permissive, roles, qual, with_check). Rule PG-POLICY-001: the table is resolved and is the relation fact of the statement; the USING and WITH CHECK expressions are conditions where the table is visible. AS takes PERMISSIVE or RESTRICTIVE; the grammar rejects another word. Source: https://www.postgresql.org/docs/17/sql-createpolicy.html.
$statement = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE POLICY p ON t AS RESTRICTIVE FOR UPDATE TO CURRENT_USER USING (a > 0) WITH CHECK (a < 10)');
$statement->toString() // => 'CREATE POLICY p ON t AS restrictive FOR UPDATE TO CURRENT_USER USING (a > 0) WITH CHECK (a < 10)'Properties§
public list<RoleSpec> $rolespublic Name $namepublic QualifiedName $tablepublic Name|null $mode = nullpublic PolicyCommand|null $command = nullpublic Scalar|null $using = nullpublic Scalar|null $check = nullMethods§
public function __construct(
public Name $name,
public QualifiedName $table,
public Name|null $mode = null,
public PolicyCommand|null $command = null,
list<RoleSpec> $roles = [],
public Scalar|null $using = null,
public Scalar|null $check = null,
)Parameters
$name | Name | The policy name |
$table | QualifiedName | The table |
$mode | Name|null | The word after AS: permissive or restrictive |
$command | PolicyCommand|null | The command after FOR |
$roles | list<RoleSpec> | The roles after TO; none means PUBLIC |
$using | Scalar|null | The USING condition |
$check | Scalar|null | The WITH CHECK condition |
Calls 4
- static-call Check::input() line 65
- function-call
in_arrayline 65 - static-call Check::listOf() line 66
- class-const RoleSpec::class() line 66
public function deriveStatement(Derivation $derivation): voidResolves the table and derives the conditions.
Parameters
$derivation | Derivation |
Calls 2
- method-call Policies::derive() line 74
- new Policies line 74
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 82
- new Targets line 82
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 6
- method-call Output::keyword() line 90
- method-call Spelling::qualified() line 91
- new Spelling line 91
- class-const NameUse::Identifier() line 93
- method-call Policies::write() line 98
- new Policies line 98
Test cases 1§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.