Skip to content

Commit 8470f41

Browse files
committed
Fix ALTER ADD INDEX tuple expression parsing
Simplified the index expression parsing in ALTER ADD INDEX to let parseExpression handle parentheses naturally. This allows tuple expressions like (a, b, c) to be parsed correctly, matching how CREATE TABLE INDEX parsing works.
1 parent e059896 commit 8470f41

File tree

4 files changed

+6
-24
lines changed

4 files changed

+6
-24
lines changed

parser/parser.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5267,16 +5267,11 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
52675267
Position: p.current.Pos,
52685268
Name: idxName,
52695269
}
5270-
// Parse expression - can be in parentheses or bare expression until TYPE keyword
5271-
if p.currentIs(token.LPAREN) {
5272-
p.nextToken()
5270+
// Parse expression - let parseExpression handle parentheses naturally
5271+
// This allows (a, b, c) to be parsed as a tuple
5272+
if !p.currentIs(token.IDENT) || strings.ToUpper(p.current.Value) != "TYPE" {
52735273
idx.Expression = p.parseExpression(LOWEST)
52745274
cmd.IndexExpr = idx.Expression
5275-
p.expect(token.RPAREN)
5276-
} else if !p.currentIs(token.IDENT) || strings.ToUpper(p.current.Value) != "TYPE" {
5277-
// Parse bare expression (not in parentheses) - ends at TYPE keyword
5278-
idx.Expression = p.parseExpression(ALIAS_PREC)
5279-
cmd.IndexExpr = idx.Expression
52805275
}
52815276
// Parse TYPE
52825277
if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "TYPE" {
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt8": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt14": true,
4-
"stmt15": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt5": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)