classInsertRows
final class InsertRows
implements Modification
uses Snapshot
Public API: explicitly declared with
@visibility public.An INSERT of rows written in VALUES.
Mirrors PostgreSQL's InsertStmt whose selectStmt is a bare VALUES list: each value is assigned to its column on its own, and may be DEFAULT. The facts follow PG-INSERT-001. Source: https://www.postgresql.org/docs/17/sql-insert.html. Status: Implemented.
$insert = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze("INSERT INTO t (a, b) VALUES (1, 'x'), (2, DEFAULT) RETURNING a");
[count($insert->statement->rows->rows()), count($insert->statement->returning), $insert->toString()] // => [2, 1, "INSERT INTO t (a, b) VALUES (1, 'x'), (2, DEFAULT) RETURNING a"]new \SqlSemantics\Platform\PostgreSql\Statement\Manipulation\InsertRows(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')), true)), [], null, new \SqlSemantics\Platform\PostgreSql\Statement\Manipulation\ValueRows([new \SqlSemantics\Platform\PostgreSql\Statement\Query\Clause\ValuesRow([new \SqlSemantics\Platform\PostgreSql\Statement\Literal\NullLiteral()])])) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstructionProperties§
public list<ColumnTarget> $columnspublic list<Target> $returningpublic CommonTables|null $withpublic TargetTable $targetpublic Overriding|null $overridingpublic ValueRows|ParenthesizedRows $rowspublic ConflictDoNothing|ConflictDoUpdate|null $conflict = nullMethods§
public function __construct(
public CommonTables|null $with,
public TargetTable $target,
list<ColumnTarget> $columns,
public Overriding|null $overriding,
public ValueRows|ParenthesizedRows $rows,
public ConflictDoNothing|ConflictDoUpdate|null $conflict = null,
list<Target> $returning = [],
)Parameters
$with | CommonTables|null | The WITH clause |
$target | TargetTable | The table written; never with ONLY |
$columns | list<ColumnTarget> | The column list in written order |
$overriding | Overriding|null | Whose values identity columns receive |
$rows | ValueRows|ParenthesizedRows | The rows |
$conflict | ConflictDoNothing|ConflictDoUpdate|null | The ON CONFLICT clause |
$returning | list<Target> | The RETURNING list in written order |
Throws
InvalidConstruction When the table is written with ONLY, or a list holds a foreign itemCalls 4
- static-call Check::input() line 71
- static-call Check::listOf() line 72
- class-const ColumnTarget::class() line 72
- class-const Target::class() line 73
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 97
- new Roots line 97
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 InsertFacts::rows() line 105
- new InsertFacts line 105
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 3
- method-call Output::node() line 113
- method-call Output::symbol() line 115
- method-call Output::keyword() line 118
Test cases 10§
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 9
InsertRuleTest::testColumnsLowersTheStepscallsInsertRuleTest::testConflictLowersDoUpdatecallsInsertRuleTest::testInferenceLowersTheConstraintNamecallsInsertRuleTest::testOverridingLowersSystemValuecallsInsertRuleTest::testRowsMakesValuesInParenthesesRowscallsInsertRuleTest::testTargetLowersTheAliascallsManipulationsTest::testStatementRoutesEveryStatementOfTheFamilycallsParenthesizedRowsTest::testRowsAnswersTheRowsInsidecallsValueRowsTest::testRowsAnswersTheRowscalls