@@ -139,6 +139,12 @@ func explainCastExprWithAlias(sb *strings.Builder, n *ast.CastExpr, alias string
139139 Node (sb , n .TypeExpr , depth + 2 )
140140 } else {
141141 typeStr := FormatDataType (n .Type )
142+ // Only escape if the DataType doesn't have parameters - this means the entire
143+ // type was parsed from a string literal and may contain unescaped quotes.
144+ // If it has parameters, FormatDataType already handles escaping.
145+ if n .Type == nil || len (n .Type .Parameters ) == 0 {
146+ typeStr = escapeStringLiteral (typeStr )
147+ }
142148 fmt .Fprintf (sb , "%s Literal \\ '%s\\ '\n " , indent , typeStr )
143149 }
144150}
@@ -711,7 +717,12 @@ func explainIsNullExpr(sb *strings.Builder, n *ast.IsNullExpr, indent string, de
711717}
712718
713719func explainCaseExpr (sb * strings.Builder , n * ast.CaseExpr , indent string , depth int ) {
714- explainCaseExprWithAlias (sb , n , "" , indent , depth )
720+ // Only output alias if it's unquoted (ClickHouse doesn't show quoted aliases)
721+ alias := ""
722+ if n .Alias != "" && ! n .QuotedAlias {
723+ alias = n .Alias
724+ }
725+ explainCaseExprWithAlias (sb , n , alias , indent , depth )
715726}
716727
717728func explainCaseExprWithAlias (sb * strings.Builder , n * ast.CaseExpr , alias string , indent string , depth int ) {
0 commit comments