Skip to content

Commit 141903c

Browse files
committed
Handle INTERVAL '2' AS alias unit syntax in parser
Support for aliases on the value expression in INTERVAL syntax, like INTERVAL '2' AS n minute. Fixes 01523_interval_operator_support_string_literal (now all 25 pass).
1 parent da40d74 commit 141903c

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

parser/expression.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,16 @@ func (p *Parser) parseInterval() ast.Expression {
14441444
// Use ALIAS_PREC to prevent consuming the unit as an alias
14451445
expr.Value = p.parseExpression(ALIAS_PREC)
14461446

1447+
// Handle INTERVAL '2' AS n minute - where AS n is alias on the value
1448+
if p.currentIs(token.AS) {
1449+
p.nextToken() // skip AS
1450+
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
1451+
alias := p.current.Value
1452+
p.nextToken()
1453+
expr.Value = p.wrapWithAlias(expr.Value, alias)
1454+
}
1455+
}
1456+
14471457
// Parse unit (interval units are identifiers like DAY, MONTH, etc.)
14481458
if p.currentIs(token.IDENT) {
14491459
expr.Unit = strings.ToUpper(p.current.Value)
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt19": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)