classDistinctOrdering
final class DistinctOrdering
Checks that DISTINCT ON and ORDER BY agree, as PostgreSQL requires.
Rule: PG-DISTINCT-ON-001. Each term denotes an output column: a position or an output name denotes that column, an expression denotes the output column that computes the same expression, and any other expression a column of its own. Walking ORDER BY from the left, a term that is also a DISTINCT ON term must not follow one that is not; when ORDER BY has such a term that is not a DISTINCT ON term, every DISTINCT ON term must have appeared before it. A violation is reported. Terminates: two passes over finite lists. Source: https://www.postgresql.org/docs/17/sql-select.html#SQL-DISTINCT. Status: Implemented.
Methods§
public function check(
list<Scalar> $distinct,
list<Scalar> $order,
list<Field|OpenStar> $projection,
Derivation $derivation,
): voidReports DISTINCT ON terms that do not match the leftmost ORDER BY terms.
Parameters
$distinct | list<Scalar> | The DISTINCT ON terms |
$order | list<Scalar> | The ORDER BY terms of the selection |
$projection | list<Field|OpenStar> | The output of the selection |
$derivation | Derivation |
Called from 1
Calls 7
- method-call DistinctOrdering::key() line 48
- method-call DistinctOrdering::find() line 53
- method-call Derivation::report() line 57
- new QueryMisuse line 57
- class-const QueryMisuseRule::DistinctOnOrderBy() line 57
- function-call
countline 64 - method-call DistinctOrdering::distinctKeys() line 64
public function key(
Scalar $term,
list<Field|OpenStar> $projection,
Derivation $derivation,
): int|ScalarAnswers the output column a term denotes: its position, or the expression when no output column computes it.
Parameters
$term | Scalar | |
$projection | list<Field|OpenStar> | |
$derivation | Derivation |
Returns
int|ScalarTest cases 1
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\DistinctOrdering::check() packages/sql-semantics-postgres/src/Rules/Query/DistinctOrdering.php:48
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\DistinctOrdering::check() packages/sql-semantics-postgres/src/Rules/Query/DistinctOrdering.php:53
Calls 7
- method-call Scalar::value() line 77
- method-call Ordering::bare() line 79
- new Ordering line 79
- method-call Ordering::named() line 80
- method-call DistinctOrdering::unwrapped() line 83
- method-call Equivalence::difference() line 85
- new Equivalence line 85
public function find(int|Scalar $key, list<int|Scalar> $keys): ?intFinds the first DISTINCT ON term with the same key, among the distinct keys.
Parameters
$key | int|Scalar | |
$keys | list<int|Scalar> |
Returns
?intTest cases 1
Called from 1
Calls 4
- method-call DistinctOrdering::distinctKeys() line 100
- function-call
is_intline 101 - method-call Equivalence::difference() line 101
- new Equivalence line 101
public function distinctKeys(list<int|Scalar> $keys): list<int|Scalar>Answers the keys without repetitions, keeping the first of equal ones.
Parameters
$keys | list<int|Scalar> |
Returns
list<int|Scalar>Test cases 1
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\DistinctOrdering::check() packages/sql-semantics-postgres/src/Rules/Query/DistinctOrdering.php:64
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\DistinctOrdering::find() packages/sql-semantics-postgres/src/Rules/Query/DistinctOrdering.php:100
Calls 3
- function-call
is_intline 121 - method-call Equivalence::difference() line 121
- new Equivalence line 121
Answers an expression without the parentheses around it, which PostgreSQL does not keep.
Parameters
$term | Scalar |
Returns
Test cases 1
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\DistinctOrdering::key() packages/sql-semantics-postgres/src/Rules/Query/DistinctOrdering.php:83
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\DistinctOrdering::key() packages/sql-semantics-postgres/src/Rules/Query/DistinctOrdering.php:85
Test cases 4§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.