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
750 stars 172 forks source link

Throws SyntaxError when parsing foreign key definition without backticks in sqlite #1952

Closed 1ilit closed 3 weeks ago

1ilit commented 3 weeks ago

Describe the bug Throws SyntaxError when parsing foreign key definition without backticks for the table name in sqlite

This works fine:

CREATE TABLE IF NOT EXISTS posts (
  user_id INTEGER NOT NULL,
  FOREIGN KEY (user_id) REFERENCES `users`(user_id)
);

This throws a syntax error:

CREATE TABLE IF NOT EXISTS posts (
  user_id INTEGER NOT NULL,
  FOREIGN KEY (user_id) REFERENCES users(user_id)
);

Database Engine SQLite

To Reproduce -the SQL that be parsed

CREATE TABLE IF NOT EXISTS posts (
  user_id INTEGER NOT NULL,
  FOREIGN KEY (user_id) REFERENCES users(user_id)
);

-the node-sql-parser version v5.2.0 -the node version v18.20.3

Expected behavior Produce ast

Additional context Minimal reproducible example: https://stackblitz.com/edit/stackblitz-starters-3nslzy?file=index.js