final class OutputPosition
    implements Scalar
    uses Snapshot
Public API: explicitly declared with @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.

Reading the field an ordering position denotesdoctest
$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'
Refusing a position that is not an integer constantdoctest
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\InvalidConstruction

Properties§

public Scalar $position
public OrderingClause $clause

Methods§

public function __construct(public Scalar $position, public OrderingClause $clause)

Parameters

$positionScalarThe integer constant as written
$clauseOrderingClauseThe clause the position is written in
Calls 3
public function value(): string
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Finds the output field at the position among the aliases of the environment.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

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

Writes the constant.

Parameters

$outOutput
Calls 1

Test 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