vitessio/vitess · error
invalid IntervalDateExpr syntax
Error message
invalid IntervalDateExpr syntax
What it means
IntervalDateExpr represents MySQL DATE_ADD/ADDATE/SUBDATE-family expressions; some helpers only make sense when the syntax is an add-family or sub-family form. When the Syntax field is none of the six known values (e.g. IntervalNone from an incompletely built AST node), the method panics rather than guessing.
Source
Thrown at go/vt/sqlparser/ast_funcs.go:2840
default:
return "Unknown GeomFromWktType"
}
}
func getAliasedTableExprFromTableName(tblName TableName) *AliasedTableExpr {
return &AliasedTableExpr{
Expr: tblName,
}
}
func (node *IntervalDateExpr) IsSubtraction() bool {
switch node.Syntax {
case IntervalDateExprDateAdd, IntervalDateExprAdddate, IntervalDateExprBinaryAdd, IntervalDateExprBinaryAddLeft, IntervalDateExprTimestampadd:
return false
case IntervalDateExprDateSub, IntervalDateExprSubdate, IntervalDateExprBinarySub:
return true
default:
panic("invalid IntervalDateExpr syntax")
}
}
func (node *IntervalDateExpr) NormalizedUnit() IntervalType {
if node.Unit == IntervalNone {
if node.Syntax == IntervalDateExprAdddate || node.Syntax == IntervalDateExprSubdate {
return IntervalDay
}
panic("IntervalDateExpr.Unit is not set")
}
return node.Unit
}
func (node *IntervalDateExpr) FnName() string {
switch node.Syntax {
case IntervalDateExprDateAdd:
return "date_add"
case IntervalDateExprDateSub:View on GitHub (pinned to 01a25a7d17)
Solutions
- Always set Syntax explicitly when constructing an IntervalDateExpr programmatically
- Update the switch (and NormalizedUnit) to handle any newly added IntervalDateExpr* constant
- Check for recent parser changes adding a new syntax constant and extend the helper accordingly
Example fix
// before
expr := &sqlparser.IntervalDateExpr{Unit: sqlparser.IntervalDay} // Syntax unset
_ = expr.IsBinarySyntax() // panics
// after
expr := &sqlparser.IntervalDateExpr{Syntax: sqlparser.IntervalDateExprDateAdd, Unit: sqlparser.IntervalDay} Defensive patterns
Strategy: validation
Validate before calling
func validSyntax(s sqlparser.IntervalDateExprSyntax) bool {
switch s {
case sqlparser.IntervalDateExprDateAdd, sqlparser.IntervalDateExprAdddate, sqlparser.IntervalDateExprBinaryAdd,
sqlparser.IntervalDateExprBinaryAddLeft, sqlparser.IntervalDateExprTimestampadd, sqlparser.IntervalDateExprDateSub,
sqlparser.IntervalDateExprSubdate, sqlparser.IntervalDateExprBinarySub:
return true
}
return false
} Prevention
- Never hand-build IntervalDateExpr without setting Syntax
- After parser upgrades, grep for IntervalDateExpr constants not covered in ast_funcs.go switches
- Construct AST nodes via parser helpers rather than struct literals
When it happens
Trigger: Calling the boolean is-add/sub helper method (on IntervalDateExpr at go/vt/sqlparser/ast_funcs.go:2840) on a node whose Syntax was never set, or on a Syntax constant added later without updating the switch.
Common situations: Hand-constructing sqlparser AST nodes in tests/tools without setting Syntax; a new IntervalDateExpr syntax variant introduced in the parser but not handled in ast_funcs.go switch statements; malformed queries bypassing normal parse paths.
Related errors
- IntervalDateExpr.Unit is not set
- switch should be exhaustive
- no columns available
- unexpected TrackedBuffer type %T
- unexepcted TrackedBuffer type %T
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/662e04ccef244ae3.
Report an issue: GitHub.