final class SortItem
    implements Clause
    uses Snapshot
Public API: explicitly declared with @visibility public.

One sort key of an ORDER BY list: an expression, a direction or ordering operator, and the place of NULLs.

Mirrors PostgreSQL's SortBy node. It is shared by queries, aggregate calls, window specifications and WITHIN GROUP. The holder derives the expression in the environment its position is evaluated in. Source: https://www.postgresql.org/docs/17/queries-order.html, https://www.postgresql.org/docs/17/sql-select.html#SQL-ORDERBY.

Reading a descending sort keydoctest
$item = new \SqlSemantics\Platform\PostgreSql\Statement\Query\SortItem(
        new \SqlSemantics\Platform\PostgreSql\Statement\Literal\Constant(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant('1')),
        \SqlSemantics\Platform\PostgreSql\Statement\Query\SortDirection::Descending,
    );
    [$item->direction->value, $item->nulls] // => ['DESC', null]
Rejecting a direction next to an ordering operatordoctest
new \SqlSemantics\Platform\PostgreSql\Statement\Query\SortItem(
        new \SqlSemantics\Platform\PostgreSql\Statement\Literal\NullLiteral(),
        \SqlSemantics\Platform\PostgreSql\Statement\Query\SortDirection::Ascending,
        new \SqlSemantics\Platform\PostgreSql\Statement\Name\OperatorName(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('<')),
    ) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstruction

Properties§

public Scalar $expression
public SortDirection|null $direction = null
public OperatorName|null $using = null
public NullsOrder|null $nulls = null

Methods§

public function __construct(
    public Scalar $expression,
    public SortDirection|null $direction = null,
    public OperatorName|null $using = null,
    public NullsOrder|null $nulls = null,
)

Parameters

$expressionScalarThe sort key
$directionSortDirection|nullThe direction written
$usingOperatorName|nullThe ordering operator written with USING
$nullsNullsOrder|nullThe place of NULLs written
Calls 1
public function deriveClause(Derivation $derivation, Environment $environment): void

Derives the sort key.

Parameters

$derivationDerivation
$environmentEnvironment
Test cases 1
Calls 1
public function render(Output $out): void

Writes the key, the direction or operator, and the place of NULLs.

Parameters

$outOutput
Test cases 2
Calls 2

Test cases 14§

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

Dedicated tests 4
Other tests reaching this symbol 10

Relations§

Instantiated in 3
Constant reads 4
Type declarations 2