classGrant
final class Grant
implements Statement
uses Snapshot
@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.
$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> $privilegespublic non-empty-list<RoleSpec> $granteespublic PrivilegeTarget $targetpublic bool $grantOption = falsepublic RoleSpec|null $grantor = nullMethods§
public function __construct(
list<Privilege> $privileges,
public PrivilegeTarget $target,
list<RoleSpec> $grantees,
public bool $grantOption = false,
public RoleSpec|null $grantor = null,
)Parameters
$privileges | list<Privilege> | The privileges in the order written; empty for ALL PRIVILEGES |
$target | PrivilegeTarget | The objects the privileges are granted on |
$grantees | list<RoleSpec> | The grantees in the order written, at least one |
$grantOption | bool | Whether WITH GRANT OPTION is written |
$grantor | RoleSpec|null | The role of GRANTED BY, when written |
Calls 4
- method-call PrivilegeLists::privileges() line 60
- new PrivilegeLists line 60
- static-call Check::listOf() line 61
- class-const RoleSpec::class() line 61
public function deriveStatement(Derivation $derivation): voidDerives the objects and reports the problems of the privileges, the grant option and the grantor.
Parameters
$derivation | Derivation |
Calls 7
- method-call PrivilegeChecks::privileges() line 69
- new PrivilegeChecks line 69
- method-call PrivilegeTarget::object() line 69
- method-call PrivilegeChecks::grantOption() line 71
- method-call RoleChecks::existing() line 74
- new RoleChecks line 74
- method-call PrivilegeTarget::deriveTarget() line 76
public function render(Output $out): voidWrites the request.
Parameters
$out | Output |
Calls 3
- method-call Output::keyword() line 84
- method-call PrivilegeLists::write() line 85
- new PrivilegeLists line 85
Test cases 7§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.