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

colnames should be optional in type definition for Alias #4

Closed
markandrus opened this issue Oct 5, 2024 · 0 comments
Closed

colnames should be optional in type definition for Alias #4

markandrus opened this issue Oct 5, 2024 · 0 comments

Comments

@markandrus
Copy link

Parsing SELECT * FROM t AS u produces a RangeVar for "t" with an Alias for "u". The type definition for Alias says colnames is required (although the comment says it is optional):

pg-parser/src/lib/ast.ts

Lines 4964 to 4969 in c613630

export type Alias = {
/** aliased rel name (never qualified) */
aliasname: string
/** optional list of column aliases */
colnames: { String: String }[]
}

The actual parse produces an Alias without colnames:

{
  "alias": {
    "aliasname": "u"
  }
}

I think the type should be updated as follows:

    /** aliased rel name (never qualified) */
    aliasname: string
    /** optional list of column aliases */
-   colnames: { String: String }[]
+   colnames?: { String: String }[]
  }

Parse SELECT * FROM t AS u with @pg-nano/parser
import { parseQuerySync } from '@pg-nano/pg-parser'

console.log(JSON.stringify(parseQuerySync('SELECT * FROM t AS u', null, 2))

/*

{
  "version": 160001,
  "stmts": [
    {
      "stmt": {
        "SelectStmt": {
          "targetList": [
            {
              "ResTarget": {
                "val": {
                  "ColumnRef": {
                    "fields": [
                      {
                        "A_Star": {}
                      }
                    ],
                    "location": 7
                  }
                },
                "location": 7
              }
            }
          ],
          "fromClause": [
            {
              "RangeVar": {
                "relname": "t",
                "inh": true,
                "relpersistence": "p",
                "alias": {
                  "aliasname": "u"
                },
                "location": 14
              }
            }
          ],
          "limitOption": "LIMIT_OPTION_DEFAULT",
          "op": "SETOP_NONE"
        }
      }
    }
  ]
}

*/
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