Skip to content

Commit 8a04ae3

Browse files
committed
Fix INSERT column list parsing to handle keyword column names
The parseInsert function was only checking for token.IDENT when parsing column lists in INSERT statements. Column names like 'key' and 'value' are keywords with their own tokens, so they were being skipped. Changed to use parseIdentifierName() which handles both IDENT tokens and keywords that can be used as identifiers.
1 parent f48af3a commit 8a04ae3

30 files changed

Lines changed: 29 additions & 263 deletions

File tree

parser/parser.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,12 +1170,13 @@ func (p *Parser) parseInsert() *ast.InsertQuery {
11701170
if p.currentIs(token.LPAREN) {
11711171
p.nextToken()
11721172
for !p.currentIs(token.RPAREN) && !p.currentIs(token.EOF) {
1173-
if p.currentIs(token.IDENT) {
1173+
pos := p.current.Pos
1174+
colName := p.parseIdentifierName()
1175+
if colName != "" {
11741176
ins.Columns = append(ins.Columns, &ast.Identifier{
1175-
Position: p.current.Pos,
1176-
Parts: []string{p.current.Value},
1177+
Position: pos,
1178+
Parts: []string{colName},
11771179
})
1178-
p.nextToken()
11791180
}
11801181
if p.currentIs(token.COMMA) {
11811182
p.nextToken()
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true,
4-
"stmt5": true,
5-
"stmt6": true
6-
}
7-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt3": 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-
"stmt4": true,
4-
"stmt7": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt5": true,
4-
"stmt6": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true,
4-
"stmt5": true,
5-
"stmt7": true,
6-
"stmt8": true
7-
}
8-
}
1+
{}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt3": true,
4-
"stmt4": true,
5-
"stmt5": true,
6-
"stmt6": true
7-
}
8-
}
1+
{}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true,
4-
"stmt5": true,
5-
"stmt6": true,
6-
"stmt7": true
7-
}
8-
}
1+
{}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt13": true,
4-
"stmt3": true
3+
"stmt13": true
54
}
65
}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt15": true,
4-
"stmt3": true,
5-
"stmt9": true
6-
}
7-
}
1+
{}

0 commit comments

Comments
 (0)