final class InsertSelect
    implements Statement
    uses Snapshot
Public API: explicitly declared with @visibility public.

An INSERT of the rows a query returns.

Rule: SQLITE-INSERT-SELECT-001. The facts follow SQLITE-INSERT-001 with the query as the source of the rows. A bare VALUES clause is not this statement but an insert of written rows. Source: https://sqlite.org/lang_insert.html. Status: Implemented.

Reading the query of an INSERTdoctest
$insert = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('INSERT INTO t (a) SELECT b FROM u');
    [$insert->statement->query->from->name->name->value, $insert->toString()] // => ['u', 'INSERT INTO t (a) SELECT b FROM u']
Refusing a bare VALUES clause as the querydoctest
$rows = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('VALUES (1)')->statement;
    new \SqlSemantics\Platform\Sqlite\Statement\Mutation\InsertSelect(new \SqlSemantics\Platform\Sqlite\Statement\Mutation\InsertInto(new \SqlSemantics\Platform\Sqlite\Statement\Mutation\MutationTarget(new \SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\QualifiedName(new \SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\Name('t')))), $rows) // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\InvalidConstruction

Properties§

public list<Upsert> $upserts
public list<ResultColumn|Star|TableStar> $returning
public InsertInto $into
public Query $query

Methods§

public function __construct(
    public InsertInto $into,
    public Query $query,
    list<Upsert> $upserts = [],
    list<ResultColumn|Star|TableStar> $returning = [],
)

Parameters

$intoInsertIntoThe head: verb, written table and column list
$queryQueryThe query that supplies the rows; not a bare VALUES clause
$upsertslist<Upsert>The ON CONFLICT clauses; only the last may omit its conflict target
$returninglist<ResultColumn|Star|TableStar>The RETURNING columns

Throws

InvalidConstruction When a RETURNING column is of no result column class
Calls 9
public function deriveStatement(Derivation $derivation): void

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

Parameters

$derivationDerivation
Calls 5
public function deriveWithin(Derivation $derivation, Environment $outer): ?QueryFact

Derives the statement inside an environment, as a trigger program does, and answers the rows it returns.

Parameters

$derivationDerivation
$outerEnvironment

Returns

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

Writes the statement.

Parameters

$outOutput
Calls 2

Test cases 12§

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

Dedicated tests 5
Other tests reaching this symbol 7

Relations§

Instantiated in 1
Constant reads 1
Type checks 2
Type declarations 2