classDelete
final class Delete
implements Modification
uses Snapshot
Public API: explicitly declared with
@visibility public.A DELETE: removal of the rows of a table that meet a condition, optionally joined with USING items.
Mirrors PostgreSQL's DeleteStmt (relation, usingClause, whereClause or CurrentOfExpr, returningList, withClause). The facts follow PG-CHANGE-001. Source: https://www.postgresql.org/docs/17/sql-delete.html. Status: Implemented.
$delete = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('DELETE FROM ONLY t USING u WHERE t.a = u.a RETURNING *');
[$delete->statement->target->table->only, $delete->toString()] // => [true, 'DELETE FROM ONLY t USING u WHERE t.a = u.a RETURNING *']Properties§
public list<Target> $returningpublic CommonTables|null $withpublic TargetTable $targetpublic Relation|null $using = nullpublic Scalar|CurrentOf|null $where = nullMethods§
public function __construct(
public CommonTables|null $with,
public TargetTable $target,
public Relation|null $using = null,
public Scalar|CurrentOf|null $where = null,
list<Target> $returning = [],
)Parameters
$with | CommonTables|null | The WITH clause |
$target | TargetTable | The table rows are deleted from |
$using | Relation|null | The USING item, or the list of USING items |
$where | Scalar|CurrentOf|null | The condition, or the cursor position |
$returning | list<Target> | The RETURNING list in written order |
Throws
InvalidConstruction When RETURNING holds a foreign itemCalls 2
- static-call Check::listOf() line 58
- class-const Target::class() line 58
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 82
- new Roots line 82
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::delete() line 90
- new ChangeFacts line 90
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 2
- method-call Output::node() line 98
- method-call Output::keyword() line 100
Test cases 13§
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 12
ChangeRuleTest::testCursorLowersTheNamecallsChangeRuleTest::testDeleteLowersEveryClausecallsChangeRuleTest::testReturningLowersTheTargetscallsChangeRuleTest::testUsingIsNullWithoutClausecallsManipulationsTest::testStatementRoutesEveryStatementOfTheFamilycallsPlacementTest::testObjectsStopsAtNestedModificationscallsSourcesTest::testStatementRefusesAModificationcallsModificationTest::testCommonTablesIsNullWithoutWithcallsModificationTest::testReturnsRowsIsTrueWithReturningcallsTargetTableTest::testAliasAnswersTheCorrelationNamecallsTargetTableTest::testDeriveRelationIgnoresACommonTableOfTheSameNamecallsTargetTableTest::testDeriveRelationResolvesTheDeclaredTablecalls