classQueryExpression
final class QueryExpression
implements Statement, Query, OutputNaming
uses Snapshot
@visibility public.A query body with a WITH clause before it, or ORDER BY, LIMIT and locking clauses after it.
Mirrors select_no_parens with clauses around a select_clause. PostgreSQL attaches the clauses to the query inside any parentheses, so ORDER BY after a parenthesized selection still sees its FROM items. A selection and a TABLE query hold the clauses written directly after them themselves; this node then holds only the WITH clause. The facts follow PG-QUERY-EXPRESSION-001. Source: https://www.postgresql.org/docs/17/sql-select.html. Status: Implemented.
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT 1 AS a UNION SELECT 2 ORDER BY a');
[$query->statement->body instanceof \SqlSemantics\Platform\PostgreSql\Statement\Query\SetOperation, count($query->statement->options->order)] // => [true, 1]new \SqlSemantics\Platform\PostgreSql\Statement\Query\QueryExpression(null, new \SqlSemantics\Platform\PostgreSql\Statement\Query\Select([]), new \SqlSemantics\Platform\PostgreSql\Statement\Query\Clause\SelectOptions(readOnly: true)) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstructionProperties§
public WithClause|null $withpublic Query $bodypublic SelectOptions|null $options = nullMethods§
public function __construct(
public WithClause|null $with,
public Query $body,
public SelectOptions|null $options = null,
)Parameters
$with | WithClause|null | The WITH clause |
$body | Query | The query body |
$options | SelectOptions|null | The ORDER BY, LIMIT and locking clauses written after the body |
Calls 1
- static-call Check::input() line 51
public function outputName(): ?NameAnswers the name of the first output column of the body.
Returns
?NameCalls 1
- method-call Query::outputName() line 64
public function deriveStatement(Derivation $derivation): voidDerives the query as a statement root.
Parameters
$derivation | Derivation |
Calls 2
- method-call QueryRoots::derive() line 72
- new QueryRoots line 72
public function deriveQuery(Derivation $derivation, Environment $outer): QueryFactDerives the WITH clause, the body and the clauses after it.
Parameters
$derivation | Derivation | |
$outer | Environment |
Returns
Calls 2
- method-call QueryExpressionFacts::derive() line 80
- new QueryExpressionFacts line 80
public function render(Output $out): voidWrites the WITH clause, the body and the clauses after it.
Parameters
$out | Output |
Calls 1
- method-call Output::node() line 88
Test cases 16§
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 15
SelectRuleTest::testAttachWrapsASetOperationcallsSourcesTest::testInsertableRefusesValuesInParenthesescallsCarriersTest::testCarryAddsAnOccurrenceNoNameReachescallsCarriersTest::testCoreUnwrapsParenthesesAndClausescallsCarriersTest::testTakeAnswersTheCarriersOfAQuerycallsCarrierTest::testDeriveRelationAnswersARowWithoutColumnscallsCarrierTest::testRenderWritesNothingcallsCommonTableFactsTest::testBindMakesTheTablesVisiblecallsCommonTableFactsTest::testMarkIsTheCommonTypeOfTheValuescallsCommonTableFactsTest::testMemberReportsASearchColumnTheTableLackscallsCommonTableFactsTest::testOrderDerivesReferencedTablesFirstcallsCommonTableFactsTest::testRecursiveFormReportsAQueryWithoutUnioncallsCommonTableFactsTest::testShapeAddsTheSearchAndCycleColumnscallsSetOperationFactsTest::testReboundBindsTheRecursiveTablecallsTableShapesTest::testInputReportsASampleOfACommonTablecalls
Relations§
Instantiated in 1
Type checks 11
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Sources::statement() packages/sql-semantics-postgres/src/Rules/Manipulation/Sources.php:35
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Carriers::core() packages/sql-semantics-postgres/src/Rules/Query/Carriers.php:36
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\ModifyingCommonTables::top() packages/sql-semantics-postgres/src/Rules/Query/Facts/ModifyingCommonTables.php:58
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\ModifyingCommonTables::top() packages/sql-semantics-postgres/src/Rules/Query/Facts/ModifyingCommonTables.php:62
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryExpressionFacts::merged() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:77
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryExpressionFacts::merged() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:78
- 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:73
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Trailing::query() packages/sql-semantics-postgres/src/Rules/Query/Trailing.php:51
- 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:66
Type declarations 4
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Carrier packages/sql-semantics-postgres/src/Rules/Query/Carrier.php:32
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Carriers packages/sql-semantics-postgres/src/Rules/Query/Carriers.php:46
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryExpressionFacts packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:45
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryExpressionFacts packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:72