xwb1989 / sqlparser

SQL Parser implemented in Go
Apache License 2.0
1.47k stars 238 forks source link

Syntax error #49

Closed dimensi0n closed 5 years ago

dimensi0n commented 5 years ago
sql := "SELECT * FROM table WHERE a = 'abc'"
stmt, err := sqlparser.Parse(sql)
if err != nil {
    panic(err)
}

I got this error

http: panic serving [::1]:50432: syntax error at position 20 near 'table'
goroutine 19 [running]:
net/http.(*conn).serve.func1(0xc0000a2960)
    /usr/local/go/src/net/http/server.go:1769 +0x139
panic(0x7624e0, 0xc000087020)
    /usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/flume-cloud-services/database/controllers.CreateQuery(0x8565a0, 0xc000136000, 0xc000112400)
    /home/rerwan/go/src/github.com/flume-cloud-services/database/controllers/query.go:25 +0x27b
net/http.HandlerFunc.ServeHTTP(0x7ece30, 0x8565a0, 0xc000136000, 0xc000112400)
    /usr/local/go/src/net/http/server.go:1995 +0x44
github.com/flume-cloud-services/database/middleware.AuthMiddleware.func1(0x8565a0, 0xc000136000, 0xc000112400)
    /home/rerwan/go/src/github.com/flume-cloud-services/database/middleware/auth.go:60 +0x351
net/http.HandlerFunc.ServeHTTP(0xc000090440, 0x8565a0, 0xc000136000, 0xc000112400)
    /usr/local/go/src/net/http/server.go:1995 +0x44
net/http.(*ServeMux).ServeHTTP(0xadf1a0, 0x8565a0, 0xc000136000, 0xc000112400)
    /usr/local/go/src/net/http/server.go:2375 +0x1d6
net/http.serverHandler.ServeHTTP(0xc0000932b0, 0x8565a0, 0xc000136000, 0xc000112400)
    /usr/local/go/src/net/http/server.go:2774 +0xa8
net/http.(*conn).serve(0xc0000a2960, 0x856ee0, 0xc00009e440)
    /usr/local/go/src/net/http/server.go:1878 +0x851
created by net/http.(*Server).Serve
    /usr/local/go/src/net/http/server.go:2884 +0x2f4

I am using the latest version of sqlparser And Golang 1.12

dimensi0n commented 5 years ago

I found what's the error, table is a reserved word

bramp commented 5 years ago

Glad you found the issue. You should be able to use the word table, as long as you escape it with backticks. E.g

SELECT * FROM `table`