nene / sql-parser-cst

Parses SQL into Concrete Syntax Tree (CST)
GNU General Public License v2.0
115 stars 7 forks source link

Named parameters fail if identifier is quoted #37

Closed imathews closed 1 year ago

imathews commented 1 year ago

This is a bit of an edge case, but for completeness:

BigQuery supports quoted identifiers for named parameters. E.g., the following is valid:

SELECT * FROM t WHERE id = @`foo`

Such escaping is required when parameter names contain any special characters (e.g. @`foo:bar`). Currently, the parser fails on the above query with the error message:

Error: Syntax Error: Unexpected "`"
Was expecting to see: [A-Z,a-z,_]
--> undefined:1:29
  |
1 | SELECT * FROM t WHERE id = @`foo`
  |                             ^
nene commented 1 year ago

Thanks for reporting.

I'll have to think a bit how exactly to support this syntax. There are some dialects which allow this sort of quoting for parameter names and others which don't. I will probably introduce another value for the paramTypes option like "@`name`".