classSetOperation
final class SetOperation
implements Statement, Query, OutputNaming
uses Snapshot
@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.
$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']$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\InvalidConstructionProperties§
public Query $leftpublic SetOperator $operatorpublic Query $rightpublic SetQuantifier|null $quantifier = nullMethods§
public function __construct(
public Query $left,
public SetOperator $operator,
public Query $right,
public SetQuantifier|null $quantifier = null,
)Parameters
$left | Query | The first operand |
$operator | SetOperator | The operator |
$right | Query | The second operand |
$quantifier | SetQuantifier|null | The ALL or DISTINCT written after the operator |
Calls 2
- static-call Check::input() line 54
- method-call SetOperator::level() line 60
public function outputName(): ?NameAnswers the name of the first output column, which the first operand gives.
Returns
?NameCalls 1
- method-call Query::outputName() line 69
public function deriveStatement(Derivation $derivation): voidDerives the set operation as a statement root.
Parameters
$derivation | Derivation |
Calls 2
- method-call QueryRoots::derive() line 77
- new QueryRoots line 77
public function deriveQuery(Derivation $derivation, Environment $outer): QueryFactDerives both operands and the combined output.
Parameters
$derivation | Derivation | |
$outer | Environment |
Returns
Calls 2
- method-call SetOperationFacts::derive() line 85
- new SetOperationFacts line 85
public function render(Output $out): voidWrites the operands around the operator and its quantifier.
Parameters
$out | Output |
Calls 2
- method-call Output::node() line 93
- method-call Output::keyword() line 95
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
SelectRuleTest::testSimpleLowersASetOperationcallsSourcesTest::testStatementAcceptsTheQueriesOfSelectStmtcallsCommonTableFactsTest::testMarkIsTheCommonTypeOfTheValuescallsCommonTableFactsTest::testMemberReportsASearchColumnTheTableLackscallsCommonTableFactsTest::testShapeAddsTheSearchAndCycleColumnscallsQueryRootsTest::testFirstFindsTheFirstSelectioncallsSetOperationFactsTest::testReboundBindsTheRecursiveTablecallsBodyFactsTest::testFirstFindsTheSelectionOfANestedQuerycallsSetQuantifierTest::testQuantifierOfUnionAllcallsCreateViewTest::testRecursiveQueryIsTheQuerycalls
Relations§
Instantiated in 1
Type checks 10
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Sources::statement() packages/sql-semantics-postgres/src/Rules/Manipulation/Sources.php:34
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\CommonTableFacts::recursiveForm() packages/sql-semantics-postgres/src/Rules/Query/Facts/CommonTableFacts.php:170
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryExpressionFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:58
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryExpressionFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:60
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryRoots::first() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryRoots.php:70
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryRoots::first() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryRoots.php:74
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Trailing::query() packages/sql-semantics-postgres/src/Rules/Query/Trailing.php:54
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Routine\BodyFacts::first() packages/sql-semantics-postgres/src/Rules/Routine/BodyFacts.php:63
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Routine\BodyFacts::first() packages/sql-semantics-postgres/src/Rules/Routine/BodyFacts.php:67
- instanceof SqlSemantics\Platform\PostgreSql\Statement\Query\QueryExpression::__construct() packages/sql-semantics-postgres/src/Statement/Query/QueryExpression.php:53
Type declarations 3
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SetOperationFacts packages/sql-semantics-postgres/src/Rules/Query/Facts/SetOperationFacts.php:51
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SetOperationFacts packages/sql-semantics-postgres/src/Rules/Query/Facts/SetOperationFacts.php:64
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SetOperationFacts packages/sql-semantics-postgres/src/Rules/Query/Facts/SetOperationFacts.php:93