Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql insert can ignore keyword into #4

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/go-test/deep"

"github.com/longbridgeapp/sqlparser"
)

Expand Down Expand Up @@ -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'`)
Expand Down
Loading