parseInsertStatement parses an INSERT statement
()
| 28 | |
| 29 | // parseInsertStatement parses an INSERT statement |
| 30 | func (p *Parser) parseInsertStatement() (ast.Statement, error) { |
| 31 | // We've already consumed the INSERT token in matchType |
| 32 | |
| 33 | // Parse INTO |
| 34 | if !p.isType(models.TokenTypeInto) { |
| 35 | return nil, p.expectedError("INTO") |
| 36 | } |
| 37 | p.advance() // Consume INTO |
| 38 | |
| 39 | // Parse table name (supports schema.table qualification and double-quoted identifiers) |
| 40 | tableName, err := p.parseQualifiedName() |
| 41 | if err != nil { |
| 42 | return nil, p.expectedError("table name") |
| 43 | } |
| 44 | |
| 45 | // Parse column list if present |
| 46 | columns := make([]ast.Expression, 0) |
| 47 | if p.isType(models.TokenTypeLParen) { |
| 48 | p.advance() // Consume ( |
| 49 | |
| 50 | for { |
| 51 | // Parse column name (supports double-quoted identifiers) |
| 52 | if !p.isIdentifier() { |
| 53 | return nil, p.expectedError("column name") |
| 54 | } |
| 55 | columns = append(columns, &ast.Identifier{Name: p.currentToken.Token.Value}) |
| 56 | p.advance() |
| 57 | |
| 58 | // Check if there are more columns |
| 59 | if !p.isType(models.TokenTypeComma) { |
| 60 | break |
| 61 | } |
| 62 | p.advance() // Consume comma |
| 63 | } |
| 64 | |
| 65 | if !p.isType(models.TokenTypeRParen) { |
| 66 | return nil, p.expectedError(")") |
| 67 | } |
| 68 | p.advance() // Consume ) |
| 69 | } |
| 70 | |
| 71 | // Parse SQL Server OUTPUT clause (between column list and VALUES) |
| 72 | var outputCols []ast.Expression |
| 73 | if p.dialect == string(keywords.DialectSQLServer) && strings.ToUpper(p.currentToken.Token.Value) == "OUTPUT" { |
| 74 | p.advance() // Consume OUTPUT |
| 75 | var err error |
| 76 | outputCols, err = p.parseOutputColumns() |
| 77 | if err != nil { |
| 78 | return nil, err |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // Parse VALUES or SELECT |
| 83 | var values [][]ast.Expression |
| 84 | var query ast.QueryExpression |
| 85 | |
| 86 | // ClickHouse-only: INSERT INTO t [(cols)] FORMAT <name> with the data |
| 87 | // payload being external (network / file). Short-circuit here — there is |
no test coverage detected