Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed deparser AST #131

Open
salisbury-espinosa opened this issue Feb 24, 2025 · 1 comment
Open

failed deparser AST #131

salisbury-espinosa opened this issue Feb 24, 2025 · 1 comment

Comments

@salisbury-espinosa
Copy link

salisbury-espinosa commented Feb 24, 2025

const result = parseQuerySync(`select from test_table WHERE status = 'complete'::text`);
const stmts = result.stmts.map(mapStmt);
deparse(stmts, {})

=>

deparser/deparser.ts:720
    if (node.val.String) {
                 ^
TypeError: Cannot read properties of undefined (reading 'String')

after fix:
https://github.com/launchql/pgsql-parser/blob/main/packages/deparser/src/deparser.ts#L720

if (node.val.String) { => if (node?.val?.String) {

result is

SELECT FROM test_table WHERE   null::undefined
@salisbury-espinosa
Copy link
Author

salisbury-espinosa commented Feb 24, 2025

select from test_table WHERE status = 'complete'

after pipeline (parseQuerySync |> deparse) result is

SELECT FROM test_table WHERE

without status = 'complete'

AST:

[
  {
    "RawStmt": {
      "stmt": {
        "SelectStmt": {
          "fromClause": [
            {
              "RangeVar": {
                "relname": "test_table",
                "inh": true,
                "relpersistence": "p",
                "location": 12
              }
            }
          ],
          "whereClause": {
            "A_Expr": {
              "kind": "AEXPR_OP",
              "name": [
                {
                  "String": {
                    "sval": "="
                  }
                }
              ],
              "lexpr": {
                "ColumnRef": {
                  "fields": [
                    {
                      "String": {
                        "sval": "status"
                      }
                    }
                  ],
                  "location": 29
                }
              },
              "rexpr": {
                "A_Const": {
                  "sval": {
                    "sval": "complete"
                  },
                  "location": 38
                }
              },
              "location": 36
            }
          },
          "limitOption": "LIMIT_OPTION_DEFAULT",
          "op": "SETOP_NONE"
        }
      },
      "stmt_location": 0
    }
  }
]

@salisbury-espinosa salisbury-espinosa changed the title invalid deparser AST with cast (::) failed deparser AST Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant