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

LOCK [TABLE] name [, ...] [IN mode MODE] [NOWAIT]: a request to lock tables for the current transaction.

Rule: PG-LOCK-001. Mirrors PostgreSQL's LockStmt (relations, mode, nowait). Without a mode the strongest one, ACCESS EXCLUSIVE, is taken; a written mode is kept as written. The word TABLE has no effect and is not kept. Facts: each table is resolved; only tables and views can be locked (RangeVarCallbackForLockTable; PG-RELATION-KIND-001). Source: https://www.postgresql.org/docs/17/sql-lock.html. Status: Implemented.

Reading the mode a LOCK takesdoctest
$operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('LOCK TABLE ONLY a, b NOWAIT');
    [$operation->statement->mode, $operation->statement->effectiveMode(), $operation->toString()] // => [null, \SqlSemantics\Platform\PostgreSql\Statement\Utility\Maintenance\LockMode::AccessExclusive, 'LOCK ONLY a, b NOWAIT']
Refusing a LOCK without a tabledoctest
new \SqlSemantics\Platform\PostgreSql\Statement\Utility\Maintenance\Lock([]) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstruction

Properties§

public non-empty-list<RelationReference> $tables
public LockMode|null $mode = null
public bool $nowait = false

Methods§

public function __construct(
    list<RelationReference> $tables,
    public LockMode|null $mode = null,
    public bool $nowait = false,
)

Parameters

$tableslist<RelationReference>The tables; at least one
$modeLockMode|nullThe lock mode, when written
$nowaitboolWhether the command fails instead of waiting for a conflicting lock
Calls 2
public function effectiveMode(): LockMode

Answers the mode the command takes: the written one, or ACCESS EXCLUSIVE.

Returns

Calls 1
public function deriveStatement(Derivation $derivation): void
public function render(Output $out): void

Writes the request.

Parameters

$outOutput
Calls 2

Test cases 3§

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

Dedicated tests 2
Other tests reaching this symbol 1

Relations§

Instantiated in 1
Type declarations 1