classOutputPosition
final class OutputPosition
implements Scalar
uses Snapshot
@visibility public.An integer constant in ORDER BY, GROUP BY or DISTINCT ON: the output column at that position, counted from one.
Rule: PG-OUTPUT-POSITION-002. The term denotes the output field at the position and has its type and NULL fact. The environment the holder derives it in lists the known output fields as aliases, in order up to the first star that cannot be expanded, and holds the relations of that star when there is one. A position past the known fields depends on the missing inputs of such a star; without one it is reported. Source: https://www.postgresql.org/docs/17/sql-select.html#SQL-ORDERBY. Status: Implemented.
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT 1 AS a ORDER BY 1');
$query->facts->scalar($query->statement->options->order[0]->expression)->resolution->field->name->value // => 'a'new \SqlSemantics\Platform\PostgreSql\Statement\Query\Clause\OutputPosition(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\NullLiteral(), \SqlSemantics\Platform\PostgreSql\Statement\Query\Problem\OrderingClause::OrderBy) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstructionProperties§
public Scalar $positionpublic OrderingClause $clauseMethods§
public function __construct(public Scalar $position, public OrderingClause $clause)Parameters
$position | Scalar | The integer constant as written |
$clause | OrderingClause | The clause the position is written in |
Calls 3
- static-call Check::input() line 51
- method-call Positions::value() line 51
- new Positions line 51
public function value(): stringAnswers the position as an exact decimal integer.
Returns
stringCalled from 1
Calls 2
- method-call Positions::value() line 59
- new Positions line 59
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactFinds the output field at the position among the aliases of the environment.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 13
- method-call Derivation::scalar() line 67
- new Environment line 67
- method-call OutputPosition::value() line 68
- function-call
strlenline 69 - function-call
str_starts_withline 69 - new ScalarFact line 72
- new AliasTarget line 72
- function-call
array_pushline 76 - new Dependent line 79
- class-const Nullability::Dependent() line 79
- new PositionOutOfRange line 81
- method-call Derivation::report() line 82
- new Invalid line 84
public function render(Output $out): voidTest cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 3
Other tests reaching this symbol 5
Relations§
Instantiated in 1
Type checks 3
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\DistinctOrdering::key() packages/sql-semantics-postgres/src/Rules/Query/DistinctOrdering.php:76
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Ordering::outputs() packages/sql-semantics-postgres/src/Rules/Query/Ordering.php:104
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Ordering::term() packages/sql-semantics-postgres/src/Rules/Query/Ordering.php:124