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

[Postgres]: Structure of `orderby` AST does not match MySQL #1943

Open tbantle22 opened 1 month ago

tbantle22 commented 1 month ago

Sorry for all the issues - having some trouble migrating to v5 as a lot of our Postgres tests are failing.

Parsing this query for MySQL and Postgres gives a different results structure. These were equivalent pre-v5 and both looked like the MySQL structure. This would be improved if the OrderBy type was not any:

SELECT col1 FROM tablename WHERE col1 = 'value' ORDER BY col2 DESC

MySQL:

{
   "orderby": [
        {
          "expr": {
            "type": "column_ref",
            "table": null,
            "column": "col2"
          },
          "type": "DESC"
        }
      ],
}

Postgres:

{
   "orderby": [
        {
          "expr": {
            "type": "column_ref",
            "table": null,
            "column": {
              "expr": {
                "type": "default",
                "value": "col2"
              }
            }
          },
          "type": "DESC",
          "nulls": null
        }
      ],
}
taozhi8833998 commented 4 weeks ago

@tbantle22 I will update MySQL syntax to be compatible with PostgreSQL.

tbantle22 commented 3 weeks ago

To clarify, I think both should look like the MySQL syntax

tbantle22 commented 3 weeks ago

To clarify, I think both should look like the MySQL syntax

I responded before I read this. As long as the syntax is the same for both MySQL and Postgres that will be a great help

taozhi8833998 commented 3 weeks ago

@tbantle22 ok got it. Sorry for the break changes.