final class OutputOrdinal
    implements Scalar
    uses Snapshot
Public API: explicitly declared with @visibility public.

A position in the select list written as an integer in ORDER BY or GROUP BY.

Rule: MYSQL-ORDINAL-001. An unsigned integer literal written as an ORDER BY or GROUP BY item denotes the select list item at that position, counting from one. The query derives the ordinal in an environment whose aliases are the output fields in order; when the select list holds a star whose columns are not all known, the environment holds the relations of that star and the position depends on their declarations. A position outside the select list is reported. Source: https://dev.mysql.com/doc/refman/8.4/en/select.html ("Columns selected for output can be referred to in ORDER BY and GROUP BY clauses using ... column positions"). Status: Implemented.

Reading the position of an ordering itemdoctest
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a, b FROM t ORDER BY 2');
    $query->statement->orderBy[0]->expression->position() // => 2
Refusing a decimal as a positiondoctest
new \SqlSemantics\Platform\MySql\Statement\Query\Clause\OutputOrdinal(new \SqlSemantics\Platform\MySql\Statement\Literal\NumberLiteral('1.0')) // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\InvalidConstruction

Properties§

public NumberLiteral $literal

Methods§

public function __construct(public NumberLiteral $literal)

Parameters

$literalNumberLiteralThe integer as written
Calls 2
public function position(): int
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives the integer and takes the facts of the output field at the position.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

Calls 11
public function render(Output $out): void

Writes the integer.

Parameters

$outOutput
Calls 1

Test cases 6§

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

Dedicated tests 2
Other tests reaching this symbol 4

Relations§

Instantiated in 1
Type checks 1