classUpdate
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.
$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']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\InvalidConstructionProperties§
public non-empty-list<Assignment|RowAssignment> $assignmentspublic list<Target> $returningpublic CommonTables|null $withpublic TargetTable $targetpublic Relation|null $from = nullpublic Scalar|CurrentOf|null $where = nullMethods§
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
$with | CommonTables|null | The WITH clause |
$target | TargetTable | The table updated |
$assignments | list<Assignment|RowAssignment> | The SET items in written order; at least one |
$from | Relation|null | The FROM item, or the list of FROM items |
$where | Scalar|CurrentOf|null | The condition, or the cursor position |
$returning | list<Target> | The RETURNING list in written order |
Throws
InvalidConstruction When there is no SET item, or a list holds a foreign itemCalls 6
- method-call ClosedList::of() line 71
- new ClosedList line 71
- class-const Assignment::class() line 71
- class-const RowAssignment::class() line 71
- static-call Check::listOf() line 72
- class-const Target::class() line 72
public function returnsRows(): boolTells whether the statement has a RETURNING list.
Returns
boolpublic function commonTables(): ?CommonTablesAnswers the WITH clause written before the statement.
Returns
public function deriveStatement(Derivation $derivation): voidDerives the statement as a root and records the rows of RETURNING as the output.
Parameters
$derivation | Derivation |
Calls 2
- method-call Roots::derive() line 96
- new Roots line 96
public function deriveQuery(Derivation $derivation, Environment $outer): QueryFactDerives every part against an outer environment and answers the rows of RETURNING.
Parameters
$derivation | Derivation | |
$outer | Environment |
Returns
Calls 2
- method-call ChangeFacts::update() line 104
- new ChangeFacts line 104
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 2
- method-call Output::node() line 112
- method-call Output::keyword() line 114
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
ChangeRuleTest::testAssignmentsLowersBothFormscallsChangeRuleTest::testColumnLowersTheStepscallsChangeRuleTest::testColumnsLowersTheTargetListcallsChangeRuleTest::testTargetLowersAnAliasWithoutAscallsChangeRuleTest::testUpdateLowersEveryClausecallsChangeRuleTest::testWhereLowersTheCursorcallsManipulationsTest::testStatementRoutesEveryStatementOfTheFamilycallsTargetTableTest::testNameAnswersTheTableNamecalls