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

Error in Convert func parsing #2110

Closed pershmaj closed 2 months ago

pershmaj commented 2 months ago

Describe the bug Throwing error when adding `HAVING DATEDIFF( DAY, CONVERT(DATE, MIN(O.Order_Date)), CONVERT(DATE,GETDATE()) )

7`

Database Engine MS SQL

To Reproduce -the SQL that be parsed `SELECT ct.Client_ID,ct.Name,ct.[Email Address],ct.Country,ct.Language,ct.Phone,ct.Teacher_ID FROM Clients_Of_The_Teacher ct INNER JOIN Orders_DE o on ct.Client_ID=o.Client_ID GROUP BY ct.Client_ID,ct.Name,ct.[Email Address],ct.Country,ct.Language,ct.Phone,ct.Teacher_ID HAVING DATEDIFF( DAY, CONVERT(DATE, MIN(O.Order_Date)), CONVERT(DATE,GETDATE()) )

7` -the node-sql-parser version v5.3.2 -the node version: node v20.17.0

Error SyntaxError: Expected "!=", "#", "#-", "#>", "#>>", "%", "&", "&&", "*", "+", ",", "-", "--", "->", "->>", "/", "/*", "<", "<<", "<=", "<>", "<@", "=", ">", ">=", ">>", "?", "?&", "?|", "@>", "AND", "BETWEEN", "IN", "IS", "LIKE", "NOT", "ON", "OR", "OVER", "REGEXP", "RLIKE", "USING", "XOR", "^", "div", "|", "||", or [ \t\n\r] but ")" found.

Expected behavior Parsed

taozhi8833998 commented 2 months ago

@pershmaj I've already fixed it, along with #2105. You can parse it when the next version is released.