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 21, 2024
1 parent 9aafbeb commit 5f71687
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion sql/planbuilder/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,14 @@ func selectExprNeedsAlias(e *ast.AliasedExpr, expr sql.Expression) bool {
}
})

return complex || e.InputExpression != expr.String()
// If the expression's string representation is quoted, trim the quotes before comparing it to the input expression.
// InputExpression is assigned in the Vitess layer, and it always trims quotes at that time, too.
exprString := expr.String()
if strings.HasPrefix(exprString, "'") && strings.HasSuffix(exprString, "'") {
exprString = exprString[1 : len(exprString)-1]
}

// If the expression's input value matches expr.String(), then we know that it is referenceable and
// does not need an alias.
return complex || e.InputExpression != exprString
}

0 comments on commit 5f71687

Please sign in to comment.