classSelect
final class Select
implements Statement, Query, Selection, OutputNaming
uses Snapshot
@visibility public.A selection: the SELECT form of PostgreSQL's SelectStmt without set operation.
Rule: PG-SELECT-001. Holds, in grammar order, DISTINCT [ON], the select list, INTO, FROM (one item, or a comma list of several), WHERE, GROUP BY with its quantifier, HAVING, WINDOW, and the ORDER BY, LIMIT and locking clauses written directly after it. The facts follow PG-SELECT-SCOPE-001. An integer constant in GROUP BY must be given as an output position. DISTINCT requires a select list. Source: https://www.postgresql.org/docs/17/sql-select.html. Status: Implemented.
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT DISTINCT a, 1 FROM t WHERE a > 1 GROUP BY a HAVING a > 2 ORDER BY a LIMIT 3');
[count($query->statement->targets), $query->statement->distinct !== null, count($query->statement->groupBy), count($query->statement->options->order), $query->toString()] // => [2, true, 1, 1, 'SELECT DISTINCT a, 1 FROM t WHERE a > 1 GROUP BY a HAVING a > 2 ORDER BY a LIMIT 3']new \SqlSemantics\Platform\PostgreSql\Statement\Query\Select([], distinct: new \SqlSemantics\Platform\PostgreSql\Statement\Query\Clause\DistinctClause()) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstructionProperties§
public list<Target> $targetspublic list<Scalar|GroupingRow|GroupingSet> $groupBypublic list<WindowDefinition> $windowspublic Relation|null $from = nullpublic Scalar|null $where = nullpublic Scalar|null $having = nullpublic DistinctClause|null $distinct = nullpublic IntoClause|null $into = nullpublic SetQuantifier|null $groupQuantifier = nullpublic SelectOptions|null $options = nullMethods§
public function __construct(
list<Target> $targets,
public Relation|null $from = null,
public Scalar|null $where = null,
list<Scalar|GroupingRow|GroupingSet> $groupBy = [],
public Scalar|null $having = null,
list<WindowDefinition> $windows = [],
public DistinctClause|null $distinct = null,
public IntoClause|null $into = null,
public SetQuantifier|null $groupQuantifier = null,
public SelectOptions|null $options = null,
)Parameters
$targets | list<Target> | The select-list items in output order |
$from | Relation|null | The FROM item, or the list of FROM items |
$where | Scalar|null | The row predicate |
$groupBy | list<Scalar|GroupingRow|GroupingSet> | The GROUP BY items |
$having | Scalar|null | The group predicate |
$windows | list<WindowDefinition> | The named windows |
$distinct | DistinctClause|null | The DISTINCT clause |
$into | IntoClause|null | The table SELECT INTO creates |
$groupQuantifier | SetQuantifier|null | The ALL or DISTINCT written after GROUP BY |
$options | SelectOptions|null | The ORDER BY, LIMIT and locking clauses written after the selection |
Calls 11
- static-call Check::listOf() line 93
- class-const Target::class() line 93
- method-call ClosedList::of() line 94
- new ClosedList line 94
- class-const Scalar::class() line 94
- class-const GroupingRow::class() line 94
- class-const GroupingSet::class() line 94
- static-call Check::input() line 96
- method-call Positions::value() line 96
- new Positions line 96
- class-const WindowDefinition::class() line 98
public function outputName(): ?NameAnswers the name of the first output column, when the select list fixes it.
Returns
?NameCalls 2
- method-call TargetNames::first() line 119
- new TargetNames line 119
public function deriveStatement(Derivation $derivation): voidDerives the selection as a statement root.
Parameters
$derivation | Derivation |
Calls 2
- method-call QueryRoots::derive() line 127
- new QueryRoots line 127
public function deriveQuery(Derivation $derivation, Environment $outer): QueryFactDerives the input, every clause and the output fields.
Parameters
$derivation | Derivation | |
$outer | Environment |
Returns
Calls 2
- method-call SelectFacts::derive() line 135
- new SelectFacts line 135
public function render(Output $out): voidWrites the clauses in grammar order.
Parameters
$out | Output |
Calls 3
- method-call Output::keyword() line 143
- method-call Output::list() line 155
- method-call Output::node() line 163
Test cases 53§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 2
Other tests reaching this symbol 51
LoweringTest::testStatementsSkipsEmptyStatementscallsFromRuleTest::testDerivedStripsTheParenthesescallsQueriesTest::testStatementLowersASelectStatementcallsSelectRuleTest::testNoParensHandsOptionsToTheSelectioncallsSelectRuleTest::testWithParensAnswersTheQueryInsidecallsPlatformTest::testLowerAnswersOneStatementPerWrittenStatementcallsDistinctOrderingTest::testKeyIsTheOutputPositioncallsCommonTableFactsTest::testBindMakesTheTablesVisiblecallsCommonTableFactsTest::testMarkIsTheCommonTypeOfTheValuescallsCommonTableFactsTest::testMemberReportsASearchColumnTheTableLackscallsCommonTableFactsTest::testOrderDerivesReferencedTablesFirstcallsCommonTableFactsTest::testRecursiveFormReportsAQueryWithoutUnioncallsCommonTableFactsTest::testShapeAddsTheSearchAndCycleColumnscallsSetOperationFactsTest::testReboundBindsTheRecursiveTablecallsLockingTest::testNamedAnswersTheItemWithTheNamecallsLockingTest::testRefusedAnswersTheRuleOfAnItemThatCannotBeLockedcallsLockingTest::testTablesMarksTheNullableSidescallsOrderingTest::testGroupPrefersTheInputColumncallsOrderingTest::testGroupReadsTheMembersOfAGroupingRowAsGroupingTermscallsOrderingTest::testSortPrefersTheOutputNamecallsPositionsTest::testValueFoldsMinusSignsAndParenthesescallsTrailingTest::testLimitAnswersTheCountWrittenLastcallsTrailingTest::testOptionsAnswersTheLastSortExpressionWithoutDirectioncallsTrailingTest::testOptionsAnswersTheLimitOnlyBeforeTheLockingcallsTrailingTest::testRelationAnswersTheLastJoinConditioncallsTrailingTest::testSelectAnswersHavingAfterGroupBycallsTrailingTest::testSelectAnswersTheLastGroupingExpressioncallsTrailingTest::testSelectAnswersTheLastUnaliasedTargetcallsTrailingTest::testSelectIsNullAfterIntoWindowOrAStarcallsFunctionShapesTest::testFunctionNameIsTheCalledNamecallsTableShapesTest::testInputReportsASampleOfACommonTablecallsJsonArrayQueryTest::testDeriveScalarReportsAQueryOfSeveralColumnscallsJsonArrayQueryTest::testOutputNameIsJsonArraycallsJsonArrayQueryTest::testRenderWritesTheQueryWithoutParenthesescallsOutputPositionTest::testDeriveScalarDenotesTheFieldcallsOutputPositionTest::testDeriveScalarDependsOnAnUnexpandedStarcallsOutputPositionTest::testValueIsTheSignedPositioncallsGroupingRowTest::testMembersKeepTheWrittenOrdercallsCommonTableExpressionTest::testRecursiveColumnsAreTheWrittenColumnscallsCommonTableExpressionTest::testRecursiveQueryIsTheStatementcallsCommonTableExpressionTest::testRenderWritesTheNameColumnsAndStatementcallsRecursiveDefinitionTest::testRecursiveColumnsAreTheWrittenNamescallsRecursiveDefinitionTest::testRecursiveQueryIsTheComputingQuerycallsWithClauseTest::testDeriveCommonTablesBindsTheTablescallsWithClauseTest::testRenderWritesRecursivecallsFunctionTableTest::testNameIsTheFunctionNamecallsJsonTableColumnTest::testColumnsImplementTheContractcallsCreateFunctionTest::testDeriveStatementLetColumnsShadowParameterscallsCreateTableAsTest::testRejectsWithDataAfterAnOpenIsJsonTestcallsCreateMaterializedViewTest::testRejectsWithDataAfterAnOpenIsJsonTestcallsCreateViewTest::testRejectsACheckOptionAfterAnOpenIsJsonTestcalls
Relations§
Instantiated in 1
Type checks 11
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Placement::into() packages/sql-semantics-postgres/src/Rules/Manipulation/Placement.php:109
- 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\QueryExpressionFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:50
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryExpressionFacts::merged() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:84
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryRoots::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryRoots.php:52
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryRoots::first() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryRoots.php:78
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Trailing::query() packages/sql-semantics-postgres/src/Rules/Query/Trailing.php:58
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Routine\BodyFacts::first() packages/sql-semantics-postgres/src/Rules/Routine/BodyFacts.php:71
- instanceof SqlSemantics\Platform\PostgreSql\Statement\Query\QueryExpression::__construct() packages/sql-semantics-postgres/src/Statement/Query/QueryExpression.php:53
- instanceof SqlSemantics\Platform\PostgreSql\Statement\Query\QueryExpression::__construct() packages/sql-semantics-postgres/src/Statement/Query/QueryExpression.php:56
- instanceof SqlSemantics\Platform\PostgreSql\Statement\Query\SetOperation::__construct() packages/sql-semantics-postgres/src/Statement/Query/SetOperation.php:56
Type declarations 7
- type SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:218
- type SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Placement packages/sql-semantics-postgres/src/Rules/Manipulation/Placement.php:106
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryRoots packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryRoots.php:68
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:58
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:174
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Trailing packages/sql-semantics-postgres/src/Rules/Query/Trailing.php:74
- type SqlSemantics\Platform\PostgreSql\Rules\Routine\BodyFacts packages/sql-semantics-postgres/src/Rules/Routine/BodyFacts.php:61