classSortItem
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.
$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]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\InvalidConstructionProperties§
public Scalar $expressionpublic SortDirection|null $direction = nullpublic OperatorName|null $using = nullpublic NullsOrder|null $nulls = nullMethods§
public function __construct(
public Scalar $expression,
public SortDirection|null $direction = null,
public OperatorName|null $using = null,
public NullsOrder|null $nulls = null,
)Parameters
$expression | Scalar | The sort key |
$direction | SortDirection|null | The direction written |
$using | OperatorName|null | The ordering operator written with USING |
$nulls | NullsOrder|null | The place of NULLs written |
Calls 1
- static-call Check::input() line 54
public function deriveClause(Derivation $derivation, Environment $environment): voidDerives the sort key.
Parameters
$derivation | Derivation | |
$environment | Environment |
Test cases 1
Calls 1
- method-call Derivation::scalar() line 62
public function render(Output $out): voidWrites the key, the direction or operator, and the place of NULLs.
Parameters
$out | Output |
Test cases 2
Calls 2
- method-call Output::node() line 70
- method-call Output::keyword() line 72
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
WindowChecksTest::testSpecificationLeavesARefinedWindowToTheWindowClausecallsClauseTest::testDeriveClauseIsOfferedByEveryPartThatMayHoldExpressionscallsFunctionCallTest::testRejectsAnOrderingWithoutArgumentscallsFunctionCallTest::testRejectsWithinGroupWithDistinctcallsFunctionCallTest::testRenderWritesDistinctVariadicAndAnInnerOrderingcallsFunctionCallTest::testRenderWritesEveryPartInOrdercallsJsonArrayAggregateTest::testDeriveScalarDerivesTheOrderingcallsJsonArrayAggregateTest::testRenderWritesTheOrderingAndTheWindowcallsWindowSpecificationTest::testDeriveClauseDerivesPartitionOrderAndFramecallsWindowSpecificationTest::testRenderWritesTheSpecificationInParenthesescalls
Relations§
Instantiated in 3
- new SqlSemantics\Platform\PostgreSql\Lowering\Query\ClauseRule::options() packages/sql-semantics-postgres/src/Lowering/Query/ClauseRule.php:61
- new SqlSemantics\Platform\PostgreSql\Lowering\Query\ClauseRule::sortClause() packages/sql-semantics-postgres/src/Lowering/Query/ClauseRule.php:139
- new SqlSemantics\Platform\PostgreSql\Lowering\Query\ClauseRule::sortClause() packages/sql-semantics-postgres/src/Lowering/Query/ClauseRule.php:140
Constant reads 4
- class-const SqlSemantics\Platform\PostgreSql\Statement\Invocation\FunctionCall::__construct() packages/sql-semantics-postgres/src/Statement/Invocation/FunctionCall.php:94
- class-const SqlSemantics\Platform\PostgreSql\Statement\Invocation\Json\Constructor\JsonArrayAggregate::__construct() packages/sql-semantics-postgres/src/Statement/Invocation/Json/Constructor/JsonArrayAggregate.php:64
- class-const SqlSemantics\Platform\PostgreSql\Statement\Invocation\WindowSpecification::__construct() packages/sql-semantics-postgres/src/Statement/Invocation/WindowSpecification.php:59
- class-const SqlSemantics\Platform\PostgreSql\Statement\Query\Clause\SelectOptions::__construct() packages/sql-semantics-postgres/src/Statement/Query/Clause/SelectOptions.php:55
Type declarations 2
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryExpressionFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:58
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::options() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:126