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

Square brackets not recognized for CREATE DATABASE in t-sql #1992

Closed 1ilit closed 1 month ago

1ilit commented 1 month ago

Describe the bug Throws syntax error when the name of the database in CREATE DATABASE is in square brackets

Database Engine Transact-SQL.

To Reproduce -the SQL that be parsed

CREATE DATABASE [MyDatabase];

-the node-sql-parser version v5.2.0 -the node version v20.11.0

Expected behavior Parse successfully

taozhi8833998 commented 1 month ago

@1ilit It can parse the sql.

const sql = 'CREATE DATABASE [MyDatabase];'
const { Parser } = require('node-sql-parser')
const parser = new Parser()
const ast = parser.astify(sql, { database: 'transactsql'  }) // please specified the database option
console.log(ast)

I will close the issue. If you still have problems, please reopen it, and show the codes you use.