final class SelectExpression
    implements SelectItem
    uses Snapshot
Public API: explicitly declared with @visibility public.

One projected expression of a select list with its optional alias.

MySQL names an item without alias after the text of its expression as the statement writes it (MYSQL-SELECT-ITEM-NAME-001), so such an item keeps the layout of that text (CORE-SPELLING-001): the expression is rendered in the spelling and with the trivia it was written with, and the output name follows from it. An item built without a layout is written, and named, in the canonical rendering of its expression. An aliased item is named by its alias and keeps no layout. Source: https://dev.mysql.com/doc/refman/8.4/en/select.html.

Reading a projected expression and its aliasdoctest
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a AS total FROM t');
    [$query->statement->items[0]->expression->name->value, $query->statement->items[0]->alias?->value] // => ['a', 'total']
Reading the text an unaliased item is written asdoctest
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT 1+1');
    [$query->statement->items[0]->layout?->text(), $query->field(0)->name?->value, $query->toString()] // => ['1+1', '1+1', 'SELECT 1+1']

Properties§

public Scalar $expression
public Name|null $alias = null
public Layout|null $layout = null
public AliasMark $mark = AliasMark::As

Methods§

public function __construct(
    public Scalar $expression,
    public Name|null $alias = null,
    public Layout|null $layout = null,
    public AliasMark $mark = AliasMark::As,
)

Parameters

$expressionScalarThe projected expression
$aliasName|nullThe output name
$layoutLayout|nullHow the expression of an unaliased item is written; null for the canonical rendering
$markAliasMarkWhether the alias is written after AS; `=` is not a select alias

Throws

InvalidConstruction When an aliased item is given a layout, or the mark does not fit the alias
Calls 3
public function render(Output $out): void

Writes the expression, in its layout when it has one, and the alias.

Parameters

$outOutput
Calls 4

Test cases 114§

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

Dedicated tests 6
Other tests reaching this symbol 108

Relations§

Instantiated in 2
Type checks 6
Type declarations 4