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.

Reading the rows of an INSERTdoctest
$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"]
Refusing ONLY on the table of an INSERTdoctest
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\InvalidConstruction

Properties§

public list<ColumnTarget> $columns
public list<Target> $returning
public CommonTables|null $with
public TargetTable $target
public Overriding|null $overriding
public ConflictDoNothing|ConflictDoUpdate|null $conflict = null

Methods§

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

$withCommonTables|nullThe WITH clause
$targetTargetTableThe table written; never with ONLY
$columnslist<ColumnTarget>The column list in written order
$overridingOverriding|nullWhose values identity columns receive
$rowsValueRows|ParenthesizedRowsThe rows
$conflictConflictDoNothing|ConflictDoUpdate|nullThe ON CONFLICT clause
$returninglist<Target>The RETURNING list in written order

Throws

InvalidConstruction When the table is written with ONLY, or a list holds a foreign item
Calls 4
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 3

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

Relations§

Instantiated in 1
Type declarations 2