diff --git a/package.json b/package.json index f3a81643..24a7ad1e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-sql-parser", - "version": "4.16.0", + "version": "4.17.0", "description": "simple node sql parser", "main": "index.js", "types": "types.d.ts", diff --git a/pegjs/bigquery.pegjs b/pegjs/bigquery.pegjs index a14c9a90..b7b88e01 100644 --- a/pegjs/bigquery.pegjs +++ b/pegjs/bigquery.pegjs @@ -2320,14 +2320,27 @@ case_else = KW_ELSE __ result:expr { } column_ref - = tbl:column_without_kw col:(__ DOT __ column_without_kw)+ { + = tbl:column_without_kw col:(__ DOT __ column_without_kw)+ __ cof:(column_offset_expr_list __ (DOT __ column_without_kw)?)? { const cols = col.map(c => c[3]) columnList.add(`select::${tbl}::${cols[0]}`) + const column = cof + ? { + column: { + expr: { + type: 'column_ref', + table: null, + column: cols[0], + subFields: cols.slice(1) + }, + offset: cof && cof[0], + suffix: cof && cof[2] && `.${cof[2][2]}`, + } + } + : { column: cols[0], subFields: cols.slice(1) } return { type: 'column_ref', table: tbl, - column: cols[0], - subFields: cols.slice(1) + ...column, }; } / col:column { diff --git a/test/bigquery.spec.js b/test/bigquery.spec.js index d5ad23a8..e734dd82 100644 --- a/test/bigquery.spec.js +++ b/test/bigquery.spec.js @@ -829,8 +829,8 @@ describe('BigQuery', () => { `WITH your_table AS ( SELECT [STRUCT(1 AS id, 'John' AS name), STRUCT(2 AS id, 'Jane' AS name)] AS some_array_column ) - SELECT some_array_column[SAFE_OFFSET(0)].id from your_table`, - "WITH your_table AS (SELECT [STRUCT(1 AS id, 'John' AS name), STRUCT(2 AS id, 'Jane' AS name)] AS some_array_column) SELECT some_array_column[SAFE_OFFSET(0)].id FROM your_table" + SELECT some_array_column[SAFE_OFFSET(0)].id from your_table where 1=1 and check_run.pull_requests[SAFE_OFFSET(0)].number = 6097 and check_run.status = 'completed' and check_run.output.title IS NOT NULL AND check_run.pull_requests[SAFE_OFFSET(0)].id is not null`, + "WITH your_table AS (SELECT [STRUCT(1 AS id, 'John' AS name), STRUCT(2 AS id, 'Jane' AS name)] AS some_array_column) SELECT some_array_column[SAFE_OFFSET(0)].id FROM your_table WHERE 1 = 1 AND check_run.pull_requests[SAFE_OFFSET(0)].number = 6097 AND check_run.status = 'completed' AND check_run.output.title IS NOT NULL AND check_run.pull_requests[SAFE_OFFSET(0)].id IS NOT NULL" ] }, {