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

A compound query: arms combined from left to right by UNION, UNION ALL, INTERSECT and EXCEPT.

An ORDER BY and a LIMIT written after the last arm order and limit the combined rows, so they belong to the compound and not to that arm. The grammar also admits them on an earlier arm, which SQLite rejects; there they stay on the arm.

Rule: SQLITE-COMPOUND-001. The facts are derived by SQLITE-COMPOUND-SCOPE-001. Source: https://sqlite.org/lang_select.html#compound_select_statements. Status: Implemented.

Reading the arms and the ordering of a compound querydoctest
$query = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('SELECT 1 AS a UNION SELECT 2 ORDER BY a LIMIT 1');
    [count($query->statement->steps), count($query->statement->orderBy), $query->statement->steps[0]->query->orderBy, $query->toString()] // => [1, 1, [], 'SELECT 1 AS a UNION SELECT 2 ORDER BY a LIMIT 1']
Refusing an ordering left on the last armdoctest
$ordered = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('SELECT 1 AS a ORDER BY a')->statement;
    new \SqlSemantics\Platform\Sqlite\Statement\Query\Compound(new \SqlSemantics\Platform\Sqlite\Statement\Query\ValuesClause([new \SqlSemantics\Platform\Sqlite\Statement\Query\ValueRow([new \SqlSemantics\Platform\Sqlite\Statement\Expression\Literal\NullLiteral()])]), [new \SqlSemantics\Platform\Sqlite\Statement\Query\CompoundStep(\SqlSemantics\Platform\Sqlite\Statement\Query\CompoundOperator::Union, $ordered)]) // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\InvalidConstruction

Properties§

public non-empty-list<CompoundStep> $steps
public list<SortTerm> $orderBy
public Limit|null $limit = null

Methods§

public function __construct(
    public Select|ValuesClause $first,
    list<CompoundStep> $steps,
    list<SortTerm> $orderBy = [],
    public Limit|null $limit = null,
)

Parameters

$firstSelect|ValuesClauseThe first arm
$stepslist<CompoundStep>The further arms in written order; at least one
$orderBylist<SortTerm>The ORDER BY terms of the combined rows
$limitLimit|nullThe LIMIT clause of the combined rows
Calls 7
public function deriveStatement(Derivation $derivation): void

Derives the compound query as a statement root and records its rows as the output.

Parameters

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

Derives the arms, the ordering and the output fields.

Parameters

$derivationDerivation
$outerEnvironment

Returns

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

Writes the arms, then the ordering and the limit.

Parameters

$outOutput
Calls 2

Test cases 35§

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

Dedicated tests 7
Other tests reaching this symbol 28

Relations§

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