Skip to content

Commit c3f8187

Browse files
committed
Add INSERT INTO FUNCTION SETTINGS support and INDEX definitions in CREATE TABLE
- Handle SETTINGS clause before VALUES in INSERT statements - Skip VALUES data properly in INSERT statements - Support INDEX and CONSTRAINT definitions in CREATE TABLE column list Parser failures reduced from 239 to 235.
1 parent ca277d5 commit c3f8187

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

parser/parser.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -880,10 +880,20 @@ func (p *Parser) parseInsert() *ast.InsertQuery {
880880
p.expect(token.RPAREN)
881881
}
882882

883+
// Parse SETTINGS before VALUES (skip for now as it's not in AST)
884+
if p.currentIs(token.SETTINGS) {
885+
p.nextToken()
886+
// Just parse and skip the settings
887+
p.parseSettingsList()
888+
}
889+
883890
// Parse VALUES or SELECT
884891
if p.currentIs(token.VALUES) {
885892
p.nextToken()
886-
// VALUES are typically provided externally, skip for now
893+
// Skip VALUES data - consume until end of statement
894+
for !p.currentIs(token.EOF) && !p.currentIs(token.SEMICOLON) && !p.currentIs(token.FORMAT) && !p.currentIs(token.SETTINGS) {
895+
p.nextToken()
896+
}
887897
} else if p.currentIs(token.SELECT) || p.currentIs(token.WITH) {
888898
ins.Select = p.parseSelectWithUnion()
889899
}
@@ -985,13 +995,31 @@ func (p *Parser) parseCreateTable(create *ast.CreateQuery) {
985995
}
986996
}
987997

988-
// Parse column definitions
998+
// Parse column definitions and indexes
989999
if p.currentIs(token.LPAREN) {
9901000
p.nextToken()
9911001
for !p.currentIs(token.RPAREN) && !p.currentIs(token.EOF) {
992-
col := p.parseColumnDeclaration()
993-
if col != nil {
994-
create.Columns = append(create.Columns, col)
1002+
// Handle INDEX definition
1003+
if p.currentIs(token.INDEX) {
1004+
p.nextToken()
1005+
// Skip index definition: INDEX name expr TYPE type GRANULARITY n
1006+
p.parseIdentifierName() // index name
1007+
// Skip expression and other index parts
1008+
for !p.currentIs(token.COMMA) && !p.currentIs(token.RPAREN) && !p.currentIs(token.EOF) {
1009+
p.nextToken()
1010+
}
1011+
} else if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "CONSTRAINT" {
1012+
// Skip CONSTRAINT definitions
1013+
p.nextToken()
1014+
p.parseIdentifierName() // constraint name
1015+
for !p.currentIs(token.COMMA) && !p.currentIs(token.RPAREN) && !p.currentIs(token.EOF) {
1016+
p.nextToken()
1017+
}
1018+
} else {
1019+
col := p.parseColumnDeclaration()
1020+
if col != nil {
1021+
create.Columns = append(create.Columns, col)
1022+
}
9951023
}
9961024
if p.currentIs(token.COMMA) {
9971025
p.nextToken()

0 commit comments

Comments
 (0)