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
780 stars 174 forks source link

Poor support for COLLATE syntax #1993

Closed LyzSg closed 1 month ago

LyzSg commented 1 month ago

Describe the bug The following example works fine in mysql, but will fail to parse here:

const { Parser } = require('node-sql-parser');
const parser = new Parser();

// use COLLATE with order by
parser.astify(
  'select * from test order by id COLLATE utf8mb4_unicode_ci'
);
//[SyntaxError]: Expected "!=", "#", "%", "&", "&&", "(", "*", "+", ",", "-", "--", "->", "->>", ".", "/", "/*", ";", "<", "<<", "<=", "<>", "=", ">", ">=", ">>", "ASC", "BETWEEN", "DESC", "FOR", "GO", "IN", "INTERSECT", "INTO", "IS", "LIKE", "LIMIT", "LOCK", "MINUS", "NOT", "ORDER", "REGEXP", "RLIKE", "UNION", "WINDOW", "XOR", "^", "div", "|", "||", [ \t\n\r], or end of input but "C" found.

// or with where
parser.astify(
  'select * from test where id COLLATE utf8mb4_unicode_ci = 1'
);
// [SyntaxError]: Expected "#", "--", "/*", ";", "FOR", "GO", "GROUP", "HAVING", "INTERSECT", "INTO", "LIMIT", "LOCK", "MINUS", "ORDER", "UNION", "WINDOW", [ \t\n\r], or end of input but "=" found.

Database Engine MySQL

To Reproduce -the node-sql-parser version 5.2.0 -the node version 18.20.3