classSelectRule
final class SelectRule
Lowers query statements and query bodies.
Rule: PG-SELECT-LOWER-001. Scope: SelectStmt, select_with_parens, select_no_parens, select_clause, simple_select, values_clause, set_quantifier, distinct_clause, opt_all_clause, opt_distinct_clause, into_clause, OptTempTableName, opt_target_list, target_list, target_el. Constructors: Select, TableQuery, ValuesList, SetOperation, ParenthesizedQuery, QueryExpression, ExpressionTarget, StarTarget, DistinctClause, IntoClause. Parentheses the grammar reads as grouping become ParenthesizedQuery; the parentheses a subquery requires are stripped by withParens. ORDER BY, LIMIT and locking clauses written directly after a selection or TABLE query belong to it; after anything else they belong to a QueryExpression. Termination: lists are flattened iteratively; nested queries recurse on the tree depth. Source: https://www.postgresql.org/docs/17/sql-select.html. Status: Implemented.
Methods§
Lowers SelectStmt.
Parameters
$statement | Node |
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 2
Calls 4
- method-call SelectRule::noParens() line 96
- new ParenthesizedQuery line 97
- method-call SelectRule::withParens() line 97
- static-call ImplementationGap::production() line 98
Lowers a query: SelectStmt, select_no_parens, select_with_parens (without its outer parentheses) or select_clause.
Parameters
$query | Node |
Throws
ImplementationGap When the node is not a queryTest cases 1
Called from 1
Calls 5
- method-call SelectRule::statement() line 110
- method-call SelectRule::noParens() line 111
- method-call SelectRule::withParens() line 112
- method-call SelectRule::clause() line 113
- static-call ImplementationGap::production() line 114
Lowers select_with_parens to the query inside its outer parentheses.
Parameters
$query | Node |
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 5
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\FromRule::derived() packages/sql-semantics-postgres/src/Lowering/Query/FromRule.php:145
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::statement() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:97
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::query() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:112
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::withParens() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:129
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::clause() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:187
Calls 4
- method-call SelectRule::noParens() line 128
- new ParenthesizedQuery line 129
- method-call SelectRule::withParens() line 129
- static-call ImplementationGap::production() line 130
Lowers select_no_parens.
Parameters
$query | Node |
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::statement() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:96
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::query() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:111
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::withParens() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:128
Calls 5
- new ClauseRule line 142
- method-call SelectRule::simple() line 145
- method-call SelectRule::attach() line 146
- method-call ClauseRule::options() line 146
- static-call ImplementationGap::production() line 153
public function attach(?Node $with, Node $clause, ?SelectOptions $options): Statement&QueryBuilds a query body with the WITH clause before it and the options after it.
Parameters
$with | ?Node | |
$clause | Node | |
$options | ?SelectOptions |
Throws
ImplementationGap When the WITH clause is not lowered to a WITH clauseTest cases 1
Called from 7
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::noParens() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:146
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::noParens() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:147
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::noParens() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:148
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::noParens() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:149
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::noParens() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:150
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::noParens() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:151
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::noParens() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:152
Calls 4
- method-call SelectRule::clause() line 164
- method-call WithRule::with() line 165
- new WithRule line 165
- new QueryExpression line 171
public function clause(Node $clause, ?SelectOptions $options): array{Statement&Query, bool}Lowers select_clause, handing the options to a selection or TABLE query that can hold them; answers the body and whether it took them.
Parameters
$clause | Node | |
$options | ?SelectOptions |
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::query() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:113
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::attach() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:164
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::simple() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:203
Calls 4
- method-call SelectRule::simple() line 186
- new ParenthesizedQuery line 187
- method-call SelectRule::withParens() line 187
- static-call ImplementationGap::production() line 188
public function simple(Node $select, ?SelectOptions $options): array{Statement&Query, bool}Lowers simple_select; answers the body and whether it took the options.
Parameters
$select | Node | |
$options | ?SelectOptions |
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::noParens() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:145
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::clause() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:186
Calls 12
- class-const SelectRule::OPERATORS() line 202
- new SetOperation line 203
- method-call SelectRule::clause() line 203
- method-call SelectRule::quantifier() line 203
- method-call SelectRule::selection() line 207
- method-call SelectRule::distinct() line 208
- method-call SelectRule::values() line 209
- new TableQuery line 210
- new TableInput line 210
- method-call FromRule::relation() line 210
- new FromRule line 210
- static-call ImplementationGap::production() line 211
public function selection(
Form $form,
?DistinctClause $distinct,
?SelectOptions $options,
): SelectLowers the clauses of the SELECT alternatives of simple_select.
Parameters
$form | Form | |
$distinct | ?DistinctClause | |
$options | ?SelectOptions |
Returns
Test cases 1
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::simple() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:207
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::simple() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:208
Calls 12
- new ClauseRule line 220
- method-call SelectRule::distinct() line 222
- method-call Form::node() line 222
- method-call ClauseRule::group() line 224
- new Select line 226
- method-call SelectRule::targets() line 227
- method-call FromRule::item() line 228
- new FromRule line 228
- method-call ClauseRule::where() line 229
- method-call ClauseRule::having() line 231
- method-call ClauseRule::windows() line 232
- method-call SelectRule::into() line 234
public function distinct(Node $clause): ?DistinctClauseLowers distinct_clause, opt_distinct_clause or opt_all_clause; ALL and no clause are null.
Parameters
$clause | Node |
Returns
Throws
ImplementationGap When the production has no ruleTest cases 2
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::simple() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:208
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::selection() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:222
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::distinct() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:252
Calls 6
- new DistinctClause line 250
- method-call ClauseRule::positioned() line 251
- new ClauseRule line 251
- class-const OrderingClause::DistinctOn() line 251
- method-call SelectRule::distinct() line 252
- static-call ImplementationGap::production() line 254
public function quantifier(Node $quantifier): ?SetQuantifierLowers set_quantifier; no quantifier is null.
Parameters
$quantifier | Node |
Returns
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 2
Calls 3
- class-const SetQuantifier::All() line 268
- class-const SetQuantifier::Distinct() line 269
- static-call ImplementationGap::production() line 271
public function into(Node $clause): ?IntoClauseLowers into_clause; no clause is null.
Parameters
$clause | Node |
Returns
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 1
Calls 4
- static-call ImplementationGap::production() line 287
- class-const SelectRule::PERSISTENCE() line 290
- new IntoClause line 292
- function-call
countline 292
public function values(Node $clause): ValuesListLowers values_clause.
Parameters
$clause | Node |
Returns
Test cases 1
Called from 1
Calls 4
- new ValuesRow line 305
- static-call ImplementationGap::production() line 310
- new ValuesList line 314
- function-call
array_reverseline 314
Lowers opt_target_list or target_list.
Parameters
$list | Node |
Returns
list<Target>Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 2
Calls 4
- method-call Lowering::items() line 333
- new ExpressionTarget line 336
- new StarTarget line 339
- static-call ImplementationGap::production() line 340
Private surface 3§
Implementation details, listed for orientation only.
private const PERSISTENCE = ['OptTempTableName: TEMPORARY opt_table qualified_name' => \SqlSemantics\Platfo…private const OPERATORS = ['simple_select: select_clause UNION set_quantifier select_clause' => \SqlSeman…private Lowering $loweringTest cases 13§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 13
SelectRuleTest::testAttachWrapsASetOperationcallsSelectRuleTest::testClauseTellsWhetherTheOptionsWereTakencallsSelectRuleTest::testDistinctWrapsAPositioncallsSelectRuleTest::testIntoKeepsThePersistencecallsSelectRuleTest::testNoParensHandsOptionsToTheSelectioncallsSelectRuleTest::testQuantifierIsNullWhenNotWrittencallsSelectRuleTest::testQueryStripsOneLayerOfParenthesescallsSelectRuleTest::testSelectionLowersEveryClausecallsSelectRuleTest::testSimpleLowersASetOperationcallsSelectRuleTest::testStatementKeepsTopLevelParenthesescallsSelectRuleTest::testTargetsLowersTheStarcallsSelectRuleTest::testValuesKeepsTheRowsInOrdercallsSelectRuleTest::testWithParensAnswersTheQueryInsidecalls
Relations§
Instantiated in 5
- new SqlSemantics\Platform\PostgreSql\Lowering\Query\ClauseRule::group() packages/sql-semantics-postgres/src/Lowering/Query/ClauseRule.php:227
- new SqlSemantics\Platform\PostgreSql\Lowering\Query\FromRule::derived() packages/sql-semantics-postgres/src/Lowering/Query/FromRule.php:145
- new SqlSemantics\Platform\PostgreSql\Lowering\Query\Queries::statement() packages/sql-semantics-postgres/src/Lowering/Query/Queries.php:44
- new SqlSemantics\Platform\PostgreSql\Lowering\Query\Queries::query() packages/sql-semantics-postgres/src/Lowering/Query/Queries.php:55
- new SqlSemantics\Platform\PostgreSql\Lowering\Query\Queries::targets() packages/sql-semantics-postgres/src/Lowering/Query/Queries.php:146
Method calls 5
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\ClauseRule::group() packages/sql-semantics-postgres/src/Lowering/Query/ClauseRule.php:227
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\FromRule::derived() packages/sql-semantics-postgres/src/Lowering/Query/FromRule.php:145
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\Queries::statement() packages/sql-semantics-postgres/src/Lowering/Query/Queries.php:44
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\Queries::query() packages/sql-semantics-postgres/src/Lowering/Query/Queries.php:55
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Query\Queries::targets() packages/sql-semantics-postgres/src/Lowering/Query/Queries.php:146