Quoted Identifiers in BigQuery dialect. #3168
-
Hello @tobymao & team - apologies if this is not the right place to ask this question! I am using the qualify function of sqlglot using the BigQuery dialect like so:
However when I try and execute the resulting DDL in BigQuery, it fails because it is quoting the tables incorrectly using double-quotes, whereas it should be quoting identifiers using backticks "`". When I look at the Tokenizer class within the BigQuery dialect class, I can see the class variables of the Tokenizer have the correct backticks in the list:
However these are not being used to qualify the tables. Please help me! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @rorynormaness, It seems like you may have missed setting the output dialect, because this is working as expected: >>> from sqlglot import parse_one
>>> from sqlglot.optimizer.qualify import qualify
>>>
>>> ddl = "create table foo as select 1 as c"
>>>
>>> ast = parse_one(ddl,dialect="bigquery")
>>> qast = qualify(ast,dialect="bigquery", quote_identifiers=True, identify=True)
>>>
>>> print(qast.sql(dialect="bigquery"))
CREATE TABLE `foo` AS SELECT 1 AS `c` |
Beta Was this translation helpful? Give feedback.
Hey @rorynormaness,
It seems like you may have missed setting the output dialect, because this is working as expected: