diff --git a/parser.go b/parser.go index a85297f..d11fef3 100644 --- a/parser.go +++ b/parser.go @@ -6,10 +6,8 @@ import ( "strings" ) -var ( - // ErrNotImplemented not implemented - ErrNotImplemented = errors.New("not implemented") -) +// ErrNotImplemented not implemented +var ErrNotImplemented = errors.New("not implemented") // Parser represents a SQL parser. type Parser struct { @@ -97,10 +95,11 @@ func (p *Parser) parseInsertStatement() (_ *InsertStatement, err error) { var stmt InsertStatement - if p.peek() != INTO { - return &stmt, p.errorExpected(p.pos, p.tok, "INTO") + // In MySQL the `INSERT INTO`, the `INTO` is optional. + // https://dev.mysql.com/doc/refman/8.0/en/insert.html + if p.peek() == INTO { + p.lex() } - p.lex() // Parse table name & optional alias. if stmt.TableName, err = p.parseTableName(); err != nil { @@ -967,7 +966,6 @@ func (p *Parser) parseBinaryExpr(prec1 int) (expr Expr, err error) { x = &BinaryExpr{X: x, Op: op, Y: y} } } - } func (p *Parser) parseExprs() (_ *Exprs, err error) { diff --git a/parser_test.go b/parser_test.go index 7dfa840..7f63a6b 100644 --- a/parser_test.go +++ b/parser_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/go-test/deep" + "github.com/longbridgeapp/sqlparser" ) @@ -468,7 +469,7 @@ func TestParser_ParseStatement(t *testing.T) { }, }) - AssertParseStatementError(t, `INSERT`, `1:6: expected INTO, found 'EOF'`) + AssertParseStatementError(t, `INSERT`, `1:6: expected table name, found 'EOF'`) AssertParseStatementError(t, `INSERT INTO`, `1:11: expected table name, found 'EOF'`) AssertParseStatementError(t, `INSERT INTO tbl AS`, `1:18: expected table alias, found 'EOF'`) AssertParseStatementError(t, `INSERT INTO tbl `, `1:16: expected DEFAULT VALUES, VALUES or SELECT, found 'EOF'`)