Skip to content

Commit 706812a

Browse files
committed
Changing selectExprNeedsAlias to consider string literal quotes
1 parent 9aafbeb commit 706812a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

sql/planbuilder/project.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,5 +243,12 @@ func selectExprNeedsAlias(e *ast.AliasedExpr, expr sql.Expression) bool {
243243
}
244244
})
245245

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

0 commit comments

Comments
 (0)