classSelectExpression
final class SelectExpression
implements SelectItem
uses Snapshot
@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.
$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']$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 $expressionpublic Name|null $alias = nullpublic Layout|null $layout = nullpublic AliasMark $mark = AliasMark::AsMethods§
public function __construct(
public Scalar $expression,
public Name|null $alias = null,
public Layout|null $layout = null,
public AliasMark $mark = AliasMark::As,
)Parameters
Throws
InvalidConstruction When an aliased item is given a layout, or the mark does not fit the aliasCalls 3
- class-const AliasMark::As() line 47
- static-call Check::input() line 49
- class-const AliasMark::Equals() line 51
public function render(Output $out): voidWrites the expression, in its layout when it has one, and the alias.
Parameters
$out | Output |
Calls 4
- method-call Output::layout() line 59
- method-call AliasMark::write() line 61
- method-call Output::name() line 62
- class-const NameUse::Alias() line 62
Test cases 114§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 6
SelectExpressionTest::testALayoutWithTrailingTriviaIsRejectedcallsSelectExpressionTest::testAnAliasedItemWithALayoutIsRejectedcallsSelectExpressionTest::testAnEqualsSignBeforeASelectAliasIsRejectedcallsSelectExpressionTest::testRenderOmitsTheAliasWhenNoneWasWrittencallsSelectExpressionTest::testRenderWritesAnItemBuiltWithoutLayoutCanonicallycallsSelectExpressionTest::testRenderWritesTheExpressionAndTheAliascalls
Other tests reaching this symbol 108
LiteralRuleTest::testConstantLowersIntroducedRadixLiteralsAndSignedNumberscallsLiteralRuleTest::testLiteralLowersEveryLiteralFormcallsLiteralRuleTest::testStringLowersAdjacentSegmentsIntroducersAndTheNationalPrefixcallsNameRuleTest::testColumnLowersEveryQualificationcallsNameRuleTest::testIdentifierDecodesEverySpellingOfANamecallsNameRuleTest::testOptionalLowersTheComponentOfALegacySystemVariablecallsVariableRuleTest::testAssignmentLowersAnAssignmentInsideAnExpressioncallsVariableRuleTest::testLegacySystemLowersTheScopeAndComponentOfMySql5callsVariableRuleTest::testUserLowersEverySpellingOfAUserVariableNamecallsVariableRuleTest::testVariableLowersUserAndSystemVariablesOfEveryGenerationcallsChainTest::testEarlierKeepsALimitBeforeTheLastOperandIn56callsChainTest::testEarlierRejectsALimitBeforeTheLastOperandIn57callsChainTest::testEarlierRejectsAnOrderingAfterTheFirstOperandOfASubqueryUnioncallsChainTest::testEnclosedKeepsTheClausesAfterTheFirstParenthesizedOperandcallsChainTest::testEnclosedRejectsAnOrderingAfterAParenthesizedOperandThatLimitsItselfcallsChainTest::testEnclosedRejectsClausesAfterALaterParenthesizedOperandcallsChainTest::testQueryKeepsTheOwnClausesOfAMiddleSelectInALeadingUnioncallsChainTest::testQueryLiftsTheClausesOfTheLastBlockcallsChainTest::testQueryOrdersAUnionAfterTheClausesOfItsLastBlockcallsQueryRulesTest::testAliasLowersColumnAndTableAliasescallsBlockTest::testBareDropsTheClausesWrittenAfterTheBlockcallsBlockTest::testFinishKeepsALaterOrderingAfterTheLockingClausesAsTheBlocksOwncallsBlockTest::testFinishKeepsASecondLimitAsTheLimitThatReplacesTheFirstcallsBlockTest::testFinishOrdersTheRowsOfABlockThatLimitsItsRowscallsBlockTest::testFinishWritesClausesInPlaceWhenNothingOfTheBlockPrecedesThemcallsBlockTest::testSelectReadsATrailingIntoWithoutClausesAsTheIntoAfterTheSelectListcallsBlockTest::testSelectRejectsTwoIntoClausescallsBlockTest::testThenAddsTheClausesWrittenAfterTheBlockcallsItemRuleTest::testExpressionKeepsTheLayoutOfAnItemNamedAfterItsTextcallsItemRuleTest::testMarkAnswersWhetherAnAliasIsWrittenAfterAscallsTrailerTest::testWrapPutsTheOrderingAndTheLockingAroundAQuerycallsTrailerTest::testWrapRejectsProcedureAnalysecallsCommonTablesTest::testShapeRenamesTheColumnsByTheColumnListcallsResultReferencesTest::testGroupingSkipsAColumnOfAnotherOccurrenceAndReportsTwoDifferentColumnscallsItemNamingTest::testNameAnswersTheAliasTheColumnNameOrTheTextcallsItemNamingTest::testNameAnswersTheConversionANonAsciiTextDependsOncallsItemNamingTest::testNameRefusesALayoutOfAnItemThatNamesItselfcallsItemNamingTest::testNameRefusesALayoutThatSpellsTheCanonicalRenderingcallsItemNamingTest::testTextAnswersTheLayoutOrTheCanonicalRenderingcallsQueryTailsTest::testExpressionWritesTheOrderingAndTheLimitOnlycallsQueryTailsTest::testLeadingWritesUnionTheQuantifierAndTheLastOperandcallsQueryTailsTest::testOperationWritesTheOperatorTheQuantifierAndTheRightOperandcallsSetFactsTest::testLeadingRefusesAnOwnLimitOnMySql57callsBlockFactsTest::testDeriveResolvesTheVariableOfTheInnermostBlockcallsBlockFactsTest::testVariablesHidesAParameterOfTheSameNamecallsBlockFactsTest::testVariablesReportsADuplicateNameAndKeepsTheFirstMeaningcallsBooleanLiteralTest::testDeriveScalarTypesFalseLikeTruecallsEscapeRuleTest::testUnderFollowsTheProfileOfAnAnalysiscallsNullLiteralTest::testRenderWritesTheKeywordInUpperCasecallsNumberLiteralTest::testDeriveScalarAnswersDecimalForAnExactNumberWithAPointcallsRadixLiteralTest::testDeriveScalarAnswersVarCharOfTheIntroducedCharacterSetcallsRadixLiteralTest::testRenderPrefixesAnOddCountOfHexadecimalDigitscallsRadixLiteralTest::testRenderQuotesBitDigitsOfEitherSpellingcallsStringLiteralTest::testDeriveScalarAnswersTheIntroducedCharacterSetcallsStringLiteralTest::testDeriveScalarAnswersTheNationalCharacterSetcallsStringLiteralTest::testDeriveScalarAnswersVarCharOfNoCharacterSetThatIsNeverNullcallsStringLiteralTest::testDeriveScalarRejectsALiteralSpelledUnderTheOtherEscapeRulecallsStringLiteralTest::testRenderDecodesAndSpellsEscapesUnderTheBackslashRulecallsStringLiteralTest::testRenderKeepsBackslashesUnderTheVerbatimRulecallsTemporalLiteralTest::testDeriveScalarAnswersDateForADateLiteralcallsTemporalLiteralTest::testDeriveScalarRejectsALiteralSpelledUnderTheOtherEscapeRulecallsColumnUseTest::testDeriveScalarAnswersTheTypeAndNullFactOfTheResolvedSlotcallsColumnUseTest::testDeriveScalarDependsOnTheDeclarationOfAnUndeclaredRelationcallsColumnUseTest::testDeriveScalarReportsAMissingColumncallsColumnUseTest::testDeriveScalarReportsAnAmbiguousColumncallsColumnUseTest::testDeriveScalarReportsAQualifierThatNamesNoRelationEvenInAnOpenContextcallsColumnUseTest::testDeriveScalarResolvesWithoutRegardToLetterCasecallsColumnUseTest::testRenderWritesTheQualifiersAndTheNameAsWrittencallsLateOrderingTest::testRenderWritesTheOrderingAfterTheLockingClausesOfTheBlockcallsQueryExpressionTest::testAnIntegerOrderingItemIsRejectedcallsQueryExpressionTest::testAnOrderingOverASingleBlockIsRejectedcallsQueryExpressionTest::testAWrapperWithoutClausesIsRejectedcallsQueryStatementTest::testAnIntoAfterTheSelectListIsRejectedcallsQueryStatementTest::testTheClausesOfASingleBlockAreRejectedcallsSelectItemTest::testAProjectedExpressionIsASelectItemcallsSelectTest::testAnIntegerOrderingItemIsRejectedcallsSelectTest::testAnIntoAfterTheClausesWithoutClausesIsRejectedcallsSelectTest::testANodeUsedAtTwoPositionsIsRejectedcallsSelectTest::testAStringLiteralUnderAnotherEscapeRuleIsRejectedcallsSelectTest::testDeriveQueryRefusesALateOrderingBefore56callsSelectTest::testDeriveStatementRefusesALateOrderingAtTheTopcallsSelectTest::testRejectsALateOrderingAfterABlockThatOrdersItsRowscallsSelectTest::testRejectsALateOrderingThatIsWrittenInPlacecallsSelectTest::testRenderBuildsSqlFromAnExplicitStructurecallsLeadingUnionTest::testRenderNeedsALastOperandWithOnlyItsOwnLimitOrLockingcallsLeadingUnionTest::testRenderNeedsMySql5ForTheFormAndMySql56ForAnOwnLimitcallsLeadingUnionTest::testRenderNeedsUnionAfterItcallsOrderedSetOperationTest::testDeriveQueryNeedsMySql56callsOrderedSetOperationTest::testDeriveQueryOrdersTheResultAndKeepsTheClausesOfTheLastSelectcallsOrderedSetOperationTest::testRejectsALastSelectWithoutClausesOfItsOwncallsOrderedSetOperationTest::testRejectsAsAnOperandOfAnotherSetOperationcallsSetOperationTest::testALastOperandWithItsOwnOrderingIsRejectedcallsSetOperationTest::testALooserOperationOnTheLeftOfIntersectIsRejectedcallsSetOperationTest::testANestedOperationOnTheRightIsRejectedcallsSetOperationTest::testAQueryExpressionOnTheRightIsRejectedcallsSetOperationTest::testAQueryStatementAsAnOperandIsRejectedcallsBlockTest::testDeriveProgramHidesAParameterWithAVariableOfTheSameNamecallsBlockTest::testDeriveProgramKeepsTheFirstMeaningOfADuplicateVariablecallsSystemVariableTest::testDeriveScalarNamesAnUnscopedVariableWithoutAScopecallsSystemVariableTest::testDeriveScalarNamesTheInstanceOfAStructuredVariablecallsSystemVariableTest::testDeriveScalarNamesTheVariableAsMissingSessionStatecallsSystemVariableTest::testRenderBuildsSqlFromAnExplicitStructurecallsSystemVariableTest::testRenderSpellsLocalAsSessioncallsUserVariableTest::testDeriveScalarKeepsTheNameAsWrittencallsUserVariableTest::testDeriveScalarNamesTheVariableAsMissingSessionStatecallsUserVariableTest::testRenderBuildsSqlFromAnExplicitStructurecallsVariableAssignmentTest::testDeriveScalarHasTheFactsOfTheValuecallsVariableAssignmentTest::testDeriveScalarRecordsTheTargetAsMissingSessionStatecalls
Relations§
Instantiated in 2
Type checks 6
- instanceof SqlSemantics\Platform\MySql\Rules\Query\Projection::items() packages/sql-semantics-mysql/src/Rules/Query/Projection.php:56
- instanceof SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::derive() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:64
- instanceof SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::aliases() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:127
- instanceof SqlSemantics\Platform\MySql\Rules\TableDefinition\ViewColumns::generated() packages/sql-semantics-mysql/src/Rules/TableDefinition/ViewColumns.php:108
- instanceof SqlSemantics\Platform\MySql\Statement\Dml\Evaluation::__construct() packages/sql-semantics-mysql/src/Statement/Dml/Evaluation.php:54
- instanceof SqlSemantics\Platform\MySql\Statement\Query\Select::__construct() packages/sql-semantics-mysql/src/Statement/Query/Select.php:125
Type declarations 4
- type SqlSemantics\Platform\MySql\Lowering\Query\Shared\ItemRule packages/sql-semantics-mysql/src/Lowering/Query/Shared/ItemRule.php:150
- type SqlSemantics\Platform\MySql\Lowering\Query\Shared\ItemRule packages/sql-semantics-mysql/src/Lowering/Query/Shared/ItemRule.php:172
- type SqlSemantics\Platform\MySql\Rules\Query\ItemNaming packages/sql-semantics-mysql/src/Rules/Query/ItemNaming.php:106
- type SqlSemantics\Platform\MySql\Rules\Query\ItemNaming packages/sql-semantics-mysql/src/Rules/Query/ItemNaming.php:190