Skip to content

Commit b7d0a23

Browse files
kyleconroyclaude
andcommitted
Add backtick quoting for special characters in type parameters
- Add needsBacktickQuoting helper to detect identifiers needing backticks - Wrap NameTypePair names with special chars in backticks Fixes 03573_json_keys_with_dots/stmt7 and 03205_json_cast_from_string/stmt5 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 50d0966 commit b7d0a23

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

internal/explain/format.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,20 @@ func formatInListAsTuple(list []ast.Expression) string {
288288
return fmt.Sprintf("Tuple_(%s)", strings.Join(parts, ", "))
289289
}
290290

291+
// needsBacktickQuoting checks if an identifier contains characters that require backtick quoting
292+
func needsBacktickQuoting(name string) bool {
293+
if name == "" {
294+
return false
295+
}
296+
// Check each character - backticks needed if name contains non-alphanumeric/underscore chars
297+
for _, c := range name {
298+
if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_') {
299+
return true
300+
}
301+
}
302+
return false
303+
}
304+
291305
// FormatDataType formats a DataType for EXPLAIN AST output
292306
func FormatDataType(dt *ast.DataType) string {
293307
if dt == nil {
@@ -313,7 +327,12 @@ func FormatDataType(dt *ast.DataType) string {
313327
params = append(params, FormatDataType(nested))
314328
} else if ntp, ok := p.(*ast.NameTypePair); ok {
315329
// Named tuple field: "name Type"
316-
params = append(params, ntp.Name+" "+FormatDataType(ntp.Type))
330+
// Wrap name in backticks if it contains special characters
331+
name := ntp.Name
332+
if needsBacktickQuoting(name) {
333+
name = "`" + name + "`"
334+
}
335+
params = append(params, name+" "+FormatDataType(ntp.Type))
317336
} else if binExpr, ok := p.(*ast.BinaryExpr); ok {
318337
// Binary expression (e.g., 'hello' = 1 for Enum types)
319338
params = append(params, formatBinaryExprForType(binExpr))
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt5": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt7": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)