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

Fails parsing BigQuery EXTRACT() format with time zone #74

Open
hrsma2i opened this issue Mar 15, 2024 · 1 comment
Open

Fails parsing BigQuery EXTRACT() format with time zone #74

hrsma2i opened this issue Mar 15, 2024 · 1 comment

Comments

@hrsma2i
Copy link

hrsma2i commented Mar 15, 2024

Thank you for this useful library!

This issue is similar to #21 .

When I parse the following SQL (a.sql) :

SELECT EXTRACT(DAYOFWEEK FROM CURRENT_TIMESTAMP() AT TIME ZONE 'Asia/Tokyo') AS as_timestamp

I caught the error:

> parse-sql@1.0.0 sql_parser_cst
> ts-node sql_parser_cst.ts

/Users/user.name/parse-sql/node_modules/sql-parser-cst/lib/main.js:40
            throw new FormattedSyntaxError_2.FormattedSyntaxError(e, sql, options.filename);
                  ^
FormattedSyntaxError: Syntax Error: Unexpected "AT"
Was expecting to see: "!=", "%", "&", "(", ")", "*", "+", "-", "->", "->>", ".", "/", "<", "<<", "<=", "<=>", "<>", "=", "==", ">", ">=", ">>", "AND", "BETWEEN", "DIV", "FILTER", "GLOB", "IN", "IS", "ISNULL", "LIKE", "MATCH", "MOD", "NOT", "NOTNULL", "OR", "OVER", "REGEXP", "RLIKE", "[", "^", "|", "||", or whitespace
--> undefined:1:51
  |
1 | SELECT EXTRACT(DAYOFWEEK FROM CURRENT_TIMESTAMP() AT TIME ZONE 'Asia/Tokyo') AS as_timestamp
  |                                                   ^
    at parse (/Users/user.name/parse-sql/node_modules/sql-parser-cst/lib/main.js:40:19)
    at Object.<anonymous> (/Users/user.name/parse-sql/sql_parser_cst.ts:12:18)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module.m._compile (/Users/user.name/parse-sql/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/user.name/parse-sql/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at phase4 (/Users/user.name/parse-sql/node_modules/ts-node/src/bin.ts:649:14)

↓ sql_parser_cst.ts

import fs from 'fs'
import path from 'path'
import { parse } from 'sql-parser-cst'

const sql_path = path.join('a.sql')
const sql = fs.readFileSync(sql_path, 'utf8')

const cst = parse(sql, {
    dialect: "bigquery",
    // These are optional:
    includeSpaces: true, // Adds spaces/tabs
    includeNewlines: true, // Adds newlines
    includeComments: true, // Adds comments
    includeRange: true, // Adds source code location data
})

console.log(cst)
@nene
Copy link
Owner

nene commented Mar 15, 2024

Thanks for reporting. Will look into it when I get a chance. Been a bit busy lately.

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

2 participants