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
818 stars 181 forks source link

`select` in mysql - cant use join + parentheses + backticks together in `from` clause #2194

Closed croconut closed 2 weeks ago

croconut commented 3 weeks ago

Describe the bug when using backticks for the table names (in combination with parentheses + joins) - astify fails, and mysql 8 considers this valid. my actual use case is pulling show create views from the db, which is why they look ugly - mysql 8 does not bother to remove unnecessary parentheses.

Database Engine mysql 8.0

To Reproduce -minimal SQL for each case:

let d = `
select *
from (\`t1\` \`eti\` join bagel on bagel.id = eti.id)
;
select *
from ((\`t1\`))
`;

let ast = parser.astify(d);

-the node-sql-parser version: 5.3.3 -the node version: 20.15.1

Expected behavior listed minimal sql statements should parse.

for the first, join should be valid from that position. for the second, i should be able to start a from clause with arbitrarily deeply nested parentheses, as long as i close them before going to the next top level clause / semi-colon.