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
789 stars 176 forks source link

Using the following SQL statement, the verification does not pass #1862

Closed alwaysli closed 5 months ago

alwaysli commented 5 months ago

Describe the bug Using the following SQL statement, the verification does not pass:

SELECT
    DATE( o.date ) AS date,
    COUNT( DISTINCT o.user_id, operation_type = 0 OR NULL ) AS operateOpenCount,
    COUNT( DISTINCT o.user_id, ( operation_type = 0 AND jump_status = 3 ) OR NULL ) AS realityOpenCount,
    COUNT( DISTINCT o.user_id, operation_type = 1 OR NULL ) AS operateCloseCount,
    COUNT( DISTINCT o.user_id, ( operation_type = 1 AND jump_status = 3 ) OR NULL ) AS realityCloseCount 
FROM
    (
SELECT
    id,
    user_id,
    operation_type,
    jump_status,
    operation_time,
    rider_type,
IF
    ( EXTRACT( HOUR FROM operation_time ) >= 16, DATE_ADD( DATE( operation_time ), INTERVAL 1 DAY ), DATE( operation_time ) ) AS date 
FROM
    labour_insurance_operation 
    ) AS o
    LEFT JOIN labour_user u ON o.user_id = u.id
    LEFT JOIN labour_user_group_user gu ON o.user_id = gu.user_id 
    AND gu.STATUS = 0 
GROUP BY
    o.date

The error message is as follows Expected "!=", "#", "%", "&", "&&", "'", "(", ")", "", "+", "-", "--", "->", "->>", ".", "/", "/", "0x", "<", "<<", "<=", "<>", "=", ">", ">=", ">>", "AND", "BETWEEN", "IN", "IS", "LIKE", "N", "NOT", "OR", "ORDER", "REGEXP", "RLIKE", "SEPARATOR", "X", "XOR", "\"", "^", "_binary", "latin1", "b", "div", "|", "||", [ \t\n\r], [A-Za-z0-9$\x80-￿], or [A-Za-z0-9_:] but "," found.

Database Engine MySQL

To Reproduce -the SQL that be parsed:SQL statements can be executed normally in navicat -the node-sql-parser version: 5.0.5 -the node version:v18.17.0

Expected behavior SQL statement detection passed

Screenshots image image