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.

Reading a policydoctest
$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> $roles
public Name $name
public QualifiedName $table
public Name|null $mode = null
public PolicyCommand|null $command = null
public Scalar|null $using = null
public Scalar|null $check = null

Methods§

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

$nameNameThe policy name
$tableQualifiedNameThe table
$modeName|nullThe word after AS: permissive or restrictive
$commandPolicyCommand|nullThe command after FOR
$roleslist<RoleSpec>The roles after TO; none means PUBLIC
$usingScalar|nullThe USING condition
$checkScalar|nullThe WITH CHECK condition
Calls 4
public function deriveStatement(Derivation $derivation): void

Resolves the table and derives the conditions.

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 6

Test cases 1§

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

Dedicated tests 1

Relations§

Instantiated in 1
Type declarations 1