final class Update
    implements Modification
    uses Snapshot
Public API: explicitly declared with @visibility public.

An UPDATE: assignments to the rows of a table that meet a condition, optionally joined with other FROM items.

Mirrors PostgreSQL's UpdateStmt (relation, targetList, fromClause, whereClause or CurrentOfExpr, returningList, withClause). The facts follow PG-CHANGE-001. Source: https://www.postgresql.org/docs/17/sql-update.html. Status: Implemented.

Reading the parts of an UPDATEdoctest
$update = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('UPDATE t AS x SET a = u.a FROM u WHERE x.a = u.a RETURNING x.a');
    [count($update->statement->assignments), $update->statement->from instanceof \SqlSemantics\Platform\PostgreSql\Statement\Relation\TableInput, $update->toString()] // => [1, true, 'UPDATE t AS x SET a = u.a FROM u WHERE x.a = u.a RETURNING x.a']
Refusing UPDATE without an assignmentdoctest
new \SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Update(null, new \SqlSemantics\Platform\PostgreSql\Statement\Manipulation\TargetTable(new \SqlSemantics\Platform\PostgreSql\Statement\Name\RelationReference(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\QualifiedName(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('t')))), []) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstruction

Properties§

public non-empty-list<Assignment|RowAssignment> $assignments
public list<Target> $returning
public CommonTables|null $with
public TargetTable $target
public Relation|null $from = null
public Scalar|CurrentOf|null $where = null

Methods§

public function __construct(
    public CommonTables|null $with,
    public TargetTable $target,
    list<Assignment|RowAssignment> $assignments,
    public Relation|null $from = null,
    public Scalar|CurrentOf|null $where = null,
    list<Target> $returning = [],
)

Parameters

$withCommonTables|nullThe WITH clause
$targetTargetTableThe table updated
$assignmentslist<Assignment|RowAssignment>The SET items in written order; at least one
$fromRelation|nullThe FROM item, or the list of FROM items
$whereScalar|CurrentOf|nullThe condition, or the cursor position
$returninglist<Target>The RETURNING list in written order

Throws

InvalidConstruction When there is no SET item, or a list holds a foreign item
Calls 6
public function returnsRows(): bool

Tells whether the statement has a RETURNING list.

Returns

bool
public function commonTables(): ?CommonTables

Answers the WITH clause written before the statement.

Returns

public function deriveStatement(Derivation $derivation): void

Derives the statement as a root and records the rows of RETURNING as the output.

Parameters

$derivationDerivation
Calls 2
public function deriveQuery(Derivation $derivation, Environment $outer): QueryFact

Derives every part against an outer environment and answers the rows of RETURNING.

Parameters

$derivationDerivation
$outerEnvironment

Returns

Calls 2
public function render(Output $out): void

Writes the statement.

Parameters

$outOutput
Calls 2

Test cases 9§

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

Dedicated tests 1
Other tests reaching this symbol 8

Relations§

Instantiated in 1
Type declarations 2