classExpressionTarget
final class ExpressionTarget
implements Target
uses Snapshot
@visibility public.A select-list item that is an expression with an optional output name.
Mirrors PostgreSQL's ResTarget with a value. Rule: PG-TARGET-001. The item contributes one field, named by its alias, else by PG-TARGET-NAME-001. Its type and NULL fact are those of the expression, except that an untyped string constant or NULL has type text once the query resolves its output. A t.* or (value).* without an alias expands into the fields it selects (PG-STAR-001); with an alias it is one composite value. Source: https://www.postgresql.org/docs/17/sql-select.html#SQL-SELECT-LIST, https://www.postgresql.org/docs/17/typeconv-select.html. Status: Implemented.
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze("SELECT 'a'");
[$query->field(0)->name->value, $query->field(0)->type->descriptor->name()] // => ['?column?', 'text']Properties§
public Scalar $expressionpublic Name|null $alias = nullMethods§
public function __construct(public Scalar $expression, public Name|null $alias = null)Parameters
$expression | Scalar | The projected expression |
$alias | Name|null | The output name written for it |
public function name(): NameAnswers the name of the field: the alias, else the name the expression gives.
Returns
Test cases 1
Called from 1
Calls 2
- method-call TargetNames::name() line 60
- new TargetNames line 60
public function project(Derivation $derivation, Environment $environment, int $position): arrayDerives the expression and answers its field, or the fields its star selects.
Parameters
$derivation | Derivation | |
$environment | Environment | |
$position | int |
Returns
arrayCalls 11
- method-call Derivation::scalar() line 68
- method-call StarExpansion::qualified() line 70
- new StarExpansion line 70
- function-call
countline 72 - method-call StarExpansion::composite() line 73
- class-const Builtin::Unknown() line 75
- new Known line 75
- class-const Builtin::Text() line 75
- new Field line 78
- new OutputSlot line 78
- method-call ExpressionTarget::name() line 78
public function render(Output $out): voidWrites the expression and the output name after AS.
Parameters
$out | Output |
Calls 3
- method-call Output::node() line 86
- method-call Output::keyword() line 88
- class-const NameUse::Label() line 88
Test cases 21§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
Other tests reaching this symbol 20
CommonTableFactsTest::testBindMakesTheTablesVisiblecallsCommonTableFactsTest::testMarkIsTheCommonTypeOfTheValuescallsCommonTableFactsTest::testMemberReportsASearchColumnTheTableLackscallsCommonTableFactsTest::testOrderDerivesReferencedTablesFirstcallsCommonTableFactsTest::testRecursiveFormReportsAQueryWithoutUnioncallsCommonTableFactsTest::testShapeAddsTheSearchAndCycleColumnscallsSetOperationFactsTest::testReboundBindsTheRecursiveTablecallsTableShapesTest::testInputReportsASampleOfACommonTablecallsJsonArrayQueryTest::testDeriveScalarReportsAQueryOfSeveralColumnscallsJsonArrayQueryTest::testOutputNameIsJsonArraycallsJsonArrayQueryTest::testRenderWritesTheQueryWithoutParenthesescallsTargetTest::testProjectIsOfferedByASelectListItemcallsCommonTableExpressionTest::testRecursiveColumnsAreTheWrittenColumnscallsCommonTableExpressionTest::testRecursiveQueryIsTheStatementcallsCommonTableExpressionTest::testRenderWritesTheNameColumnsAndStatementcallsRecursiveDefinitionTest::testRecursiveColumnsAreTheWrittenNamescallsRecursiveDefinitionTest::testRecursiveQueryIsTheComputingQuerycallsWithClauseTest::testDeriveCommonTablesBindsTheTablescallsWithClauseTest::testRenderWritesRecursivecallsCreateFunctionTest::testDeriveStatementLetColumnsShadowParameterscalls
Relations§
Instantiated in 3
- new SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::targets() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:336
- new SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::targets() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:337
- new SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule::targets() packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:338