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

A request to grant privileges on objects to roles.

Rule: PG-GRANT-001. Mirrors GrantStmt with is_grant: the privileges (an empty list is ALL PRIVILEGES), the objects, the grantees, WITH GRANT OPTION and GRANTED BY. The words PRIVILEGES after ALL and GROUP before a grantee have no effect and are not kept. The objects are derived by their target (tables are resolved, PG-GRANT-RELATION-001); the privileges are checked against the object kind (PG-PRIVILEGE-CHECK-001); a grant option for PUBLIC on named objects and PUBLIC as the grantor are reported. Source: https://www.postgresql.org/docs/17/sql-grant.html, https://www.postgresql.org/docs/17/ddl-priv.html. Status: Implemented.

Reading the parts of a grantdoctest
$operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('GRANT ALL PRIVILEGES ON accounts TO GROUP staff WITH GRANT OPTION');
    [$operation->statement->privileges, $operation->statement->grantOption, $operation->toString()] // => [[], true, 'GRANT ALL ON TABLE accounts TO staff WITH GRANT OPTION']

Properties§

public list<Privilege> $privileges
public non-empty-list<RoleSpec> $grantees
public bool $grantOption = false
public RoleSpec|null $grantor = null

Methods§

public function __construct(
    list<Privilege> $privileges,
    public PrivilegeTarget $target,
    list<RoleSpec> $grantees,
    public bool $grantOption = false,
    public RoleSpec|null $grantor = null,
)

Parameters

$privilegeslist<Privilege>The privileges in the order written; empty for ALL PRIVILEGES
$targetPrivilegeTargetThe objects the privileges are granted on
$granteeslist<RoleSpec>The grantees in the order written, at least one
$grantOptionboolWhether WITH GRANT OPTION is written
$grantorRoleSpec|nullThe role of GRANTED BY, when written
Calls 4
public function deriveStatement(Derivation $derivation): void

Derives the objects and reports the problems of the privileges, the grant option and the grantor.

Parameters

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

Writes the request.

Parameters

$outOutput
Calls 3

Test cases 7§

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

Dedicated tests 3
Other tests reaching this symbol 4

Relations§

Instantiated in 1