classOutputOrdinal
final class OutputOrdinal
implements Scalar
uses Snapshot
@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.
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a, b FROM t ORDER BY 2');
$query->statement->orderBy[0]->expression->position() // => 2new \SqlSemantics\Platform\MySql\Statement\Query\Clause\OutputOrdinal(new \SqlSemantics\Platform\MySql\Statement\Literal\NumberLiteral('1.0')) // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\InvalidConstructionProperties§
public NumberLiteral $literalMethods§
public function __construct(public NumberLiteral $literal)Parameters
$literal | NumberLiteral | The integer as written |
Calls 2
- static-call Check::input() line 52
- class-const NumberForm::Integer() line 52
public function position(): intAnswers the position, counting from one; a position beyond the integer range of PHP answers the largest integer.
Returns
intTest cases 1
Called from 2
- method-call SqlSemantics\Platform\MySql\Statement\Query\Clause\OutputOrdinal::deriveScalar() packages/sql-semantics-mysql/src/Statement/Query/Clause/OutputOrdinal.php:71
- method-call SqlSemantics\Platform\MySql\Statement\Query\Clause\OutputOrdinal::deriveScalar() packages/sql-semantics-mysql/src/Statement/Query/Clause/OutputOrdinal.php:82
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the integer and takes the facts of the output field at the position.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 11
- method-call Derivation::scalar() line 70
- method-call OutputOrdinal::position() line 71
- new ScalarFact line 73
- new AliasTarget line 73
- function-call
array_pushline 77 - new Dependent line 80
- class-const Nullability::Dependent() line 80
- new OrdinalOutOfRange line 82
- function-call
countline 82 - method-call Derivation::report() line 83
- new Invalid line 85
public function render(Output $out): voidTest cases 6§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.