Skip to content

BigQuery: Error parsing dot-star after array subscript #112

Description

@nawhi

Hi, thank you for this great library!

I noticed that in the BigQuery dialect, dot-star after an array subscript fails to parse.

Reproduction with v0.33.1:

import { parse } from "sql-parser-cst";

const sql = `
with x as (
  select [struct(1 as id, 'test' as name)] as arr
)
select arr[safe_offset(0)].*
from x
`;

parse(sql, { dialect: "bigquery" });

This throws the following error:

/path/to/project/node_modules/.pnpm/sql-parser-cst@0.33.1/node_modules/sql-parser-cst/lib/main.js:40
            throw new FormattedSyntaxError_2.FormattedSyntaxError(e, sql, options.filename);
                  ^

FormattedSyntaxError: Syntax Error: Unexpected "*"
Was expecting to see: "`", [A-Z,a-z,_], or whitespace
--> undefined:5:28
  |
5 | select arr[safe_offset(0)].*
  |                            ^
    at parse (/path/to/project/node_modules/.pnpm/sql-parser-cst@0.33.1/node_modules/sql-parser-cst/lib/main.js:40:19)
    at file:///path/to/project/index.js:11:1
    at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)

Node.js v22.16.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions