classInsertSelect
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.
$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']$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\InvalidConstructionProperties§
public list<Upsert> $upsertspublic list<ResultColumn|Star|TableStar> $returningpublic InsertInto $intopublic Query $queryMethods§
public function __construct(
public InsertInto $into,
public Query $query,
list<Upsert> $upserts = [],
list<ResultColumn|Star|TableStar> $returning = [],
)Parameters
$into | InsertInto | The head: verb, written table and column list |
$query | Query | The query that supplies the rows; not a bare VALUES clause |
$upserts | list<Upsert> | The ON CONFLICT clauses; only the last may omit its conflict target |
$returning | list<ResultColumn|Star|TableStar> | The RETURNING columns |
Throws
InvalidConstruction When a RETURNING column is of no result column classCalls 9
- static-call Check::input() line 63
- static-call Check::listOf() line 64
- class-const Upsert::class() line 64
- function-call
countline 66 - method-call ClosedList::of() line 68
- new ClosedList line 68
- class-const ResultColumn::class() line 68
- class-const Star::class() line 68
- class-const TableStar::class() line 68
public function deriveStatement(Derivation $derivation): voidDerives the statement as a root and records the rows of RETURNING as the output.
Parameters
$derivation | Derivation |
Calls 5
- method-call ProgramOnly::outsideProgram() line 76
- new ProgramOnly line 76
- method-call InsertSelect::deriveWithin() line 77
- method-call Derivation::environment() line 77
- method-call Derivation::output() line 79
public function deriveWithin(Derivation $derivation, Environment $outer): ?QueryFactDerives the statement inside an environment, as a trigger program does, and answers the rows it returns.
Parameters
$derivation | Derivation | |
$outer | Environment |
Returns
Called from 1
Calls 2
- method-call InsertFacts::derive() line 88
- new InsertFacts line 88
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 2
- method-call Output::node() line 96
- method-call Output::keyword() line 101
Test cases 12§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
InsertSelectTest::testDeriveWithinAnswersNullWithoutReturningcallsInsertSelectTest::testDeriveWithinBindsTheWithClauseForTheQueryAndReturnsTheTargetRowcallsInsertSelectTest::testRejectsABareValuesClausecallsInsertSelectTest::testRejectsANonLastUpsertWithoutAConflictTargetcallsInsertSelectTest::testRenderWritesIntoQueryUpsertsAndReturningcalls
Other tests reaching this symbol 7
MutationRuleTest::testCommandLowersEachDataChangeFormcallsMutationRuleTest::testInsertLowersWrittenRowsAndEveryOtherSourceAsAQuerycallsWithRuleTest::testOptionalIsNullWithoutAWithClauseOnADataChangecallsTriggerRuleTest::testProgramLowersEveryStatementInWrittenOrdercallsInsertFactsTest::testDeriveBindsTheWithClauseAndReturnsTheTargetRowcallsInsertFactsTest::testDeriveSkipsTheCountWhenEitherSideIsOpencallsInsertIntoTest::testRenderWritesTheVerbTheResolutionTheTargetAndTheColumnscalls
Relations§
Instantiated in 1
Constant reads 1
Type checks 2
- instanceof SqlSemantics\Platform\Sqlite\Rules\Mutation\TriggerFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/TriggerFacts.php:71
- instanceof SqlSemantics\Platform\Sqlite\Statement\Trigger\CreateTrigger::__construct() packages/sql-semantics-sqlite/src/Statement/Trigger/CreateTrigger.php:89