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

UNION, INTERSECT or EXCEPT of two queries.

Mirrors a SelectStmt with op and all. An operand is a selection, a VALUES list, a TABLE query, another set operation or a parenthesized query; a selection or TABLE query with ORDER BY, LIMIT or locking clauses must be parenthesized. Because INTERSECT binds more tightly and operators associate from the left, a set operation that would need parentheses to keep its place is refused as an operand. The facts follow PG-SET-OPERATION-001. Source: https://www.postgresql.org/docs/17/queries-union.html. Status: Implemented.

Reading a set operationdoctest
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT 1 AS a UNION ALL SELECT 2');
    [$query->statement->operator->value, $query->statement->quantifier->value, $query->field(0)->name->value] // => ['UNION', 'ALL', 'a']
Refusing a right operand that would re-associatedoctest
$one = new \SqlSemantics\Platform\PostgreSql\Statement\Query\ValuesList([new \SqlSemantics\Platform\PostgreSql\Statement\Query\Clause\ValuesRow([new \SqlSemantics\Platform\PostgreSql\Statement\Literal\NullLiteral()])]);
    $two = new \SqlSemantics\Platform\PostgreSql\Statement\Query\ValuesList([new \SqlSemantics\Platform\PostgreSql\Statement\Query\Clause\ValuesRow([new \SqlSemantics\Platform\PostgreSql\Statement\Literal\NullLiteral()])]);
    $three = new \SqlSemantics\Platform\PostgreSql\Statement\Query\ValuesList([new \SqlSemantics\Platform\PostgreSql\Statement\Query\Clause\ValuesRow([new \SqlSemantics\Platform\PostgreSql\Statement\Literal\NullLiteral()])]);
    new \SqlSemantics\Platform\PostgreSql\Statement\Query\SetOperation($one, \SqlSemantics\Platform\PostgreSql\Statement\Query\SetOperator::Union, new \SqlSemantics\Platform\PostgreSql\Statement\Query\SetOperation($two, \SqlSemantics\Platform\PostgreSql\Statement\Query\SetOperator::Except, $three)) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstruction

Properties§

public Query $left
public SetOperator $operator
public Query $right
public SetQuantifier|null $quantifier = null

Methods§

public function __construct(
    public Query $left,
    public SetOperator $operator,
    public Query $right,
    public SetQuantifier|null $quantifier = null,
)

Parameters

$leftQueryThe first operand
$operatorSetOperatorThe operator
$rightQueryThe second operand
$quantifierSetQuantifier|nullThe ALL or DISTINCT written after the operator
Calls 2
public function outputName(): ?Name

Answers the name of the first output column, which the first operand gives.

Returns

Calls 1
public function deriveStatement(Derivation $derivation): void

Derives the set operation as a statement root.

Parameters

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

Derives both operands and the combined output.

Parameters

$derivationDerivation
$outerEnvironment

Returns

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

Writes the operands around the operator and its quantifier.

Parameters

$outOutput
Calls 2

Test cases 11§

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 10

Relations§

Instantiated in 1
Type checks 10
Type declarations 3