vitessio/vitess · error
UnescapeID err: unexpected single backtick at position %d in
Error message
UnescapeID err: unexpected single backtick at position %d in '%s'
What it means
Returned by sqlescape.UnescapeID when a backtick-quoted identifier contains an unexpected single backtick at the given position, i.e. a stray or unpaired backtick inside the identifier.
Source
Thrown at go/sqlescape/ids.go:75
// UnescapeID reverses any backticking in the input string by EscapeID.
func UnescapeID(in string) (string, error) {
l := len(in)
if l == 0 || in == "``" {
return "", fmt.Errorf("UnescapeID err: invalid input identifier '%s'", in)
}
if l == 1 {
if in[0] == '`' {
return "", errors.New("UnescapeID err: invalid input identifier '`'")
}
return in, nil
}
first, last := in[0], in[l-1]
if first == '`' && last != '`' {
return "", fmt.Errorf("UnescapeID err: unexpected single backtick at position %d in '%s'", 0, in)
}
if first != '`' && last == '`' {
return "", fmt.Errorf("UnescapeID err: unexpected single backtick at position %d in '%s'", l, in)
}
if first != '`' && last != '`' {
if idx := strings.IndexByte(in, '`'); idx != -1 {
return "", fmt.Errorf("UnescapeID err: no outer backticks found in the identifier '%s'", in)
}
return in, nil
}
in = in[1 : l-1]
if found := strings.Contains(in, "`"); !found {
return in, nil
}
var buf strings.BuilderView on GitHub (pinned to 01a25a7d17)
Solutions
- Ensure identifiers are escaped/paired with EscapeID rather than hand-built strings
- Validate balanced backticks before calling UnescapeID
- Trace where the string was truncated and fix the producer
Example fix
// before
name, err := sqlescape.UnescapeID(raw)
// after
if strings.Count(raw, "`")%2 != 0 {
return fmt.Errorf("unbalanced backticks in %q", raw)
}
name, err := sqlescape.UnescapeID(raw) Defensive patterns
Strategy: validation
Validate before calling
func balancedBackticks(in string) bool { return strings.Count(in, "`")%2 == 0 } Type guard
func isQuotedID(in string) bool { return len(in) >= 2 && in[0] == '`' && in[len(in)-1] == '`' } Try / catch
if !isQuotedID(raw) && strings.Contains(raw, "`") {
return fmt.Errorf("malformed identifier %q", raw)
}
name, err := sqlescape.UnescapeID(raw) Prevention
- Always use sqlescape.EscapeID to produce escaped identifiers
- Do not build backticked names by hand or via string splitting
- Guard against truncation when storing/transmitting identifiers
When it happens
Trigger: Calling UnescapeID on a string like "`tablename" — opening backtick present, closing one missing.
Common situations: String truncation (e.g. log parsing, config splitting on backticks), hand-built identifiers where only one side was quoted, copy-paste errors.
Related errors
- UnescapeID err: no outer backticks found in the identifier '
- UnescapeID err: invalid input identifier '%s'
- unknown SQL type %q at %s
- --batch-size only allowed when all queries are CREATE TABLE|
- missing value for 'rate'
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/e0176e5d05286ba3.
Report an issue: GitHub.