classTrailing
final class Trailing
Finds the expression a query is written to end with, so that a statement can tell whether a token it writes after the query would continue that expression.
Rule: PG-QUERY-TRAILING-001. A query ends with an expression when its last written clause does: the last unaliased select-list item, a FROM item that ends with a JOIN ... ON condition, WHERE, the last GROUP BY expression, HAVING, the last ORDER BY expression without a direction, NULLS or USING, or a LIMIT or OFFSET count. A set operation ends where its right operand does, a query with a WITH clause or trailing clauses where its body or those clauses do. VALUES, TABLE, a parenthesized query, a WINDOW clause, a locking clause, FETCH, an alias and INTO end with a closing token or a name. CREATE VIEW ... WITH CHECK OPTION and CREATE TABLE AS / CREATE MATERIALIZED VIEW ... WITH [NO] DATA write WITH after the query, which an IS JSON test at the end would take (Precedence::takesUniqueness). Terminates: each step descends into a part of a finite tree. Source: https://github.com/postgres/postgres/blob/REL_17_2/src/backend/parser/gram.y (simple_select, select_limit, json_key_uniqueness_constraint_opt). Status: Implemented.
Methods§
Answers the expression a query ends with, or null when it ends with a closing token or a name.
Parameters
$query | Query |
Returns
Test cases 3
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Trailing::query() packages/sql-semantics-postgres/src/Rules/Query/Trailing.php:52
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Trailing::query() packages/sql-semantics-postgres/src/Rules/Query/Trailing.php:55
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Trailing::takesWith() packages/sql-semantics-postgres/src/Rules/Query/Trailing.php:66
Calls 3
- method-call Trailing::options() line 52
- method-call Trailing::query() line 52
- method-call Trailing::select() line 58
public function takesWith(Query $query): boolTells whether a WITH written after a query would continue an IS JSON test the query ends with.
Parameters
$query | Query |
Returns
boolTest cases 1
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\CreateTableAs::__construct() packages/sql-semantics-postgres/src/Statement/Table/CreateTableAs.php:55
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\View\CreateMaterializedView::__construct() packages/sql-semantics-postgres/src/Statement/Table/View/CreateMaterializedView.php:77
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\View\CreateView::__construct() packages/sql-semantics-postgres/src/Statement/Table/View/CreateView.php:80
Calls 3
- method-call Trailing::query() line 66
- method-call Precedence::takesUniqueness() line 68
- new Precedence line 68
Answers the expression a SELECT ends with, or null.
Parameters
$select | Select |
Returns
Test cases 4
Called from 1
Calls 3
- method-call Trailing::options() line 77
- function-call
countline 82 - method-call Trailing::relation() line 89
public function options(SelectOptions $options): ?ScalarAnswers the expression the ORDER BY, limit and locking clauses end with, or null.
Parameters
$options | SelectOptions |
Returns
Test cases 2
Called from 2
Calls 2
- method-call Trailing::limit() line 104
- function-call
countline 106
Answers the count a limit ends with, or null for LIMIT ALL and FETCH.
Parameters
$limit | RowLimit |
Returns
Test cases 1
Answers the JOIN ... ON condition a FROM item ends with, or null.
Parameters
$relation | Relation |
Returns
Test cases 1
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Trailing::select() packages/sql-semantics-postgres/src/Rules/Query/Trailing.php:89
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Trailing::relation() packages/sql-semantics-postgres/src/Rules/Query/Trailing.php:132
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Trailing::relation() packages/sql-semantics-postgres/src/Rules/Query/Trailing.php:140
Calls 2
- method-call Trailing::relation() line 132
- function-call
countline 132
Test cases 12§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 12
TrailingTest::testLimitAnswersTheCountWrittenLastcallsTrailingTest::testOptionsAnswersTheLastSortExpressionWithoutDirectioncallsTrailingTest::testOptionsAnswersTheLimitOnlyBeforeTheLockingcallsTrailingTest::testQueryFollowsTheClausesAfterTheBodycallsTrailingTest::testQueryFollowsTheRightOperandOfASetOperationcallsTrailingTest::testQueryIsNullForValuescallsTrailingTest::testRelationAnswersTheLastJoinConditioncallsTrailingTest::testSelectAnswersHavingAfterGroupBycallsTrailingTest::testSelectAnswersTheLastGroupingExpressioncallsTrailingTest::testSelectAnswersTheLastUnaliasedTargetcallsTrailingTest::testSelectIsNullAfterIntoWindowOrAStarcallsTrailingTest::testTakesWithFindsAnOpenIsJsonTestAtTheEndcalls
Relations§
Instantiated in 3
- new SqlSemantics\Platform\PostgreSql\Statement\Table\CreateTableAs::__construct() packages/sql-semantics-postgres/src/Statement/Table/CreateTableAs.php:55
- new SqlSemantics\Platform\PostgreSql\Statement\Table\View\CreateMaterializedView::__construct() packages/sql-semantics-postgres/src/Statement/Table/View/CreateMaterializedView.php:77
- new SqlSemantics\Platform\PostgreSql\Statement\Table\View\CreateView::__construct() packages/sql-semantics-postgres/src/Statement/Table/View/CreateView.php:80
Method calls 3
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\CreateTableAs::__construct() packages/sql-semantics-postgres/src/Statement/Table/CreateTableAs.php:55
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\View\CreateMaterializedView::__construct() packages/sql-semantics-postgres/src/Statement/Table/View/CreateMaterializedView.php:77
- method-call SqlSemantics\Platform\PostgreSql\Statement\Table\View\CreateView::__construct() packages/sql-semantics-postgres/src/Statement/Table/View/CreateView.php:80