final class DistinctOrdering
Restricted visibility: declared "@visibility SqlSemantics\Platform\PostgreSql". Code outside that scope must not name this declaration.

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,
): void

Reports DISTINCT ON terms that do not match the leftmost ORDER BY terms.

Parameters

$distinctlist<Scalar>The DISTINCT ON terms
$orderlist<Scalar>The ORDER BY terms of the selection
$projectionlist<Field|OpenStar>The output of the selection
$derivationDerivation
Called from 1
Calls 7
public function find(int|Scalar $key, list<int|Scalar> $keys): ?int

Finds the first DISTINCT ON term with the same key, among the distinct keys.

Parameters

$keyint|Scalar
$keyslist<int|Scalar>

Returns

?int
Test cases 1
Called from 1
Calls 4
public function distinctKeys(list<int|Scalar> $keys): list<int|Scalar>

Test cases 4§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 4

Relations§

Instantiated in 1
Method calls 1