Skip to content

Commit 2c1a679

Browse files
committed
Add INTERVAL fix and IS DISTINCT FROM support
- Fix INTERVAL expression parsing to not consume unit as alias - Add IS [NOT] DISTINCT FROM comparison syntax support
1 parent 406a417 commit 2c1a679

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

parser/expression.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,10 @@ func (p *Parser) parseInterval() ast.Expression {
948948
}
949949
p.nextToken() // skip INTERVAL
950950

951-
expr.Value = p.parseExpression(LOWEST)
951+
// Use ALIAS_PREC to prevent consuming the unit as an alias
952+
expr.Value = p.parseExpression(ALIAS_PREC)
952953

953-
// Parse unit
954+
// Parse unit (interval units are identifiers like DAY, MONTH, etc.)
954955
if p.currentIs(token.IDENT) {
955956
expr.Unit = strings.ToUpper(p.current.Value)
956957
p.nextToken()
@@ -1298,6 +1299,26 @@ func (p *Parser) parseIsExpression(left ast.Expression) ast.Expression {
12981299
}
12991300
}
13001301

1302+
// IS [NOT] DISTINCT FROM expr
1303+
if p.currentIs(token.DISTINCT) {
1304+
p.nextToken() // skip DISTINCT
1305+
if p.currentIs(token.FROM) {
1306+
p.nextToken() // skip FROM
1307+
right := p.parseExpression(COMPARE)
1308+
// IS NOT DISTINCT FROM is same as =, IS DISTINCT FROM is same as !=
1309+
op := "="
1310+
if not {
1311+
op = "!="
1312+
}
1313+
return &ast.BinaryExpr{
1314+
Position: pos,
1315+
Left: left,
1316+
Op: op,
1317+
Right: right,
1318+
}
1319+
}
1320+
}
1321+
13011322
return left
13021323
}
13031324

0 commit comments

Comments
 (0)