Skip to content

[TransactSQL] Missing astify cases for TransactSQL #2299

@albertyanzz

Description

@albertyanzz

First, thank you for all your work on this project! Truly incredible stuff.

I've been working with an MSSQL database (so using the TransactSQL database type) and came across some cases that astify couldn't handle (and probably should).

Describe the bug
A clear and concise description of what the bug is.

  • This query: "SELECT * FROM (SELECT * FROM dummy_table) AS dummy_table_alias"

    • after passing it through astify and then passing the result of that through sqlify, the parsed result is "SELECT * FROM (SELECT * FROM [dummy_table]) AS [dummy_table_alias]"
    • seems like there are some issues with subqueries that have the [] identifiers
  • This query doesn't astify in TransactSQL: "SELECT STRING_AGG(DISTINCT column_name, ',') AS aggregated_values FROM table_name;"

    • It works with PostgreSQL astify
  • JSON PATH is not handled: "SELECT column_name FROM table_name FOR JSON PATH"

    • XML PATH works for certain queries, but not in this straightforward case either "SELECT column_name FROM table_name FOR XML PATH"
  • The OFFSET, FETCH NEXT pattern
    SELECT * FROM transactions ORDER BY created_at OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY

Database Engine
TransactSQL

To Reproduce
-the SQL that be parsed:

  • "SELECT * FROM (SELECT * FROM [dummy_table]) AS [dummy_table_alias]"
  • "SELECT STRING_AGG(DISTINCT column_name, ',') AS aggregated_values FROM table_name"
  • "SELECT column_name FROM table_name FOR JSON PATH"
    -the node-sql-parser version: 5.3.6
    -the node version: >=14.20

Expected behavior

  • The above queries should work after an astify -> sqlify -> astify operation
    • If a query is the output of sqlify, then it should be astify-able
  • Additional astify cases to work with valid TransactSQL queries

Thank you!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions