taozhi8833998 / node-sql-parser

Parse simple SQL statements into an abstract syntax tree (AST) with the visited tableList and convert it back to SQL
https://taozhi8833998.github.io/node-sql-parser/
Apache License 2.0
823 stars 184 forks source link

astify throw error with column name `key` #2117

Closed zackshen closed 2 months ago

zackshen commented 2 months ago

Describe the bug

const { Parser } = require('node-sql-parser');
const parser = new Parser();
const ast = parser.astify('SELECT * FROM xxxxx WHERE key = "value1"'); // mysql sql grammer parsed by default

error

[SyntaxError]: Expected "#", "(", "--", ".", "/*", or [ \t\n\r] but "=" found.

if i changed key to ky , key1 , astify successfully.

Database Engine MySQL

To Reproduce -the SQL that be parsed: SELECT * FROM xxxxx WHERE key = "value1" -the node-sql-parser: 5.3.2 -the node version: 20.3.1

Expected behavior astify successfully.

Screenshots no screenshot.

Additional context no context.

taozhi8833998 commented 2 months ago

@zackshen key is a reserved keyword in MySQL, so please wrap it by ` in MySQL.

SELECT * FROM xxxxx WHERE `key` = "value1"
zackshen commented 2 months ago

thanks @taozhi8833998