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

[Athena & Transact SQL] Support double quoted table mentions in select statements #2240

Closed tobiasheldring closed 2 hours ago

tobiasheldring commented 12 hours ago

Describe the bug Add below tests, quoting the table name in the select statement is parsed correctly in the other dialects, but not for Athena or Transact SQL

// athena.spec.js
    it('should support double quoted table mentions in selects', () => {
      const sql = `SELECT
      "my_table"."my_column"
    FROM
      "my_table"`
      expect(getParsedSql(sql)).to.be.equal('SELECT `my_table`.`my_column` FROM `my_table`')
    })
// transactsql.spec.ts
    it('should support double quoted table mentions in selects', () => {
      const sql = `SELECT
      "my_table"."my_column"
    FROM
      "my_table"`
      expect(getParsedSql(sql)).to.be.equal('SELECT [my_table].[my_column] FROM [my_table]')
    })

Database Engine Athena & Transact SQL

tobiasheldring commented 10 hours ago

I am very unfamiliar with .pegjs, but comparing with postgresql.pegjs I managed to find a possible solution! https://github.com/tobiasheldring/node-sql-parser/pull/5/files