sqlparser icon indicating copy to clipboard operation
sqlparser copied to clipboard

parse error

Open xinlushi opened this issue 4 years ago • 3 comments

func main() { sql := "SELECT * FROM table WHERE a = 'abc'" stmt, err := sqlparser.Parse(sql) if err != nil { fmt.Printf("%s",err.Error()) }

// Otherwise do something with stmt
switch stmt := stmt.(type) {
case *sqlparser.Select:
	_ = stmt
case *sqlparser.Insert:
}

fmt.Printf("stmt :%v", stmt)

}

result err: syntax error at position 20 near 'table'

xinlushi avatar Sep 10 '21 07:09 xinlushi

Table is a reserved word. Either wrap it in backtics or use a different name for your table.

On Fri, 10 Sep 2021, 12:58 am xinlushi, @.***> wrote:

func main() { sql := "SELECT * FROM table WHERE a = 'abc'" stmt, err := sqlparser.Parse(sql) if err != nil { fmt.Printf("%s",err.Error()) }

// Otherwise do something with stmt switch stmt := stmt.(type) { case *sqlparser.Select: _ = stmt case *sqlparser.Insert: }

fmt.Printf("stmt :%v", stmt)

}

result err: syntax error at position 20 near 'table'stmt :

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/xwb1989/sqlparser/issues/68, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABHG4YUIQS3UPWCFL6U2B3UBG3A3ANCNFSM5DYZCVUA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

bramp avatar Sep 10 '21 14:09 bramp

Please replace the example, this is the code of the example

xinlushi avatar Sep 13 '21 06:09 xinlushi

There is a table in the database ‘information_schema’ as ‘tables’, this problem causes this table to be accessed abnormally

Mrsandman327 avatar Nov 14 '22 06:11 Mrsandman327