Skip to content

Commit

Permalink
Changing selectExprNeedsAlias to consider string literal quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
fulghum committed Oct 18, 2024
1 parent 9aafbeb commit 706812a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sql/planbuilder/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,12 @@ func selectExprNeedsAlias(e *ast.AliasedExpr, expr sql.Expression) bool {
}
})

return complex || e.InputExpression != expr.String()
// If the expression's input value matches expr.String() (or a quoted version of it), then we
// know that it is referenceable and does not need an alias. Note that when InputExpression is
// assigned, in Vitess, it always trims quotes from the input expression.
exprString := expr.String()
inputExpressionMatch := strings.EqualFold(e.InputExpression, exprString) ||
strings.EqualFold("'"+e.InputExpression+"'", exprString)

return complex || !inputExpressionMatch
}

0 comments on commit 706812a

Please sign in to comment.