Skip to content

Commit 5a31cd5

Browse files
kyleconroyclaude
andcommitted
Fix INTERVAL parsing to stop before AND operators (#120)
Use AND_PREC instead of ALIAS_PREC when parsing INTERVAL values to prevent consuming subsequent AND expressions as part of the interval. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8bd61bf commit 5a31cd5

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

parser/expression.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,8 +1716,9 @@ func (p *Parser) parseInterval() ast.Expression {
17161716
}
17171717
p.nextToken() // skip INTERVAL
17181718

1719-
// Use ALIAS_PREC to prevent consuming the unit as an alias
1720-
expr.Value = p.parseExpression(ALIAS_PREC)
1719+
// Use AND_PREC to stop before AND/OR operators, but still allow arithmetic operations
1720+
// This ensures INTERVAL '5 MINUTES' AND ... doesn't consume the AND
1721+
expr.Value = p.parseExpression(AND_PREC)
17211722

17221723
// Handle INTERVAL '2' AS n minute - where AS n is alias on the value
17231724
// Only consume AS if it's followed by an identifier AND that identifier is followed by an interval unit
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt9": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)