Skip to content

Commit

Permalink
Fix(bigquery): treat HASH as a reserved keyword (#1721)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas authored Jun 5, 2023
1 parent 4f31a50 commit 95f7ac7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sqlglot/dialects/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ class Generator(generator.Generator):
exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED,
}

RESERVED_KEYWORDS = {*generator.Generator.RESERVED_KEYWORDS, "hash"}

def array_sql(self, expression: exp.Array) -> str:
first_arg = seq_get(expression.expressions, 0)
if isinstance(first_arg, exp.Subqueryable):
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_bigquery(self):
"CREATE TABLE IF NOT EXISTS foo AS SELECT * FROM bla EXCEPT DISTINCT (SELECT * FROM bar) LIMIT 0"
)

self.validate_all("SELECT 1 AS hash", write={"bigquery": "SELECT 1 AS `hash`"})
self.validate_all('x <> ""', write={"bigquery": "x <> ''"})
self.validate_all('x <> """"""', write={"bigquery": "x <> ''"})
self.validate_all("x <> ''''''", write={"bigquery": "x <> ''"})
Expand Down

0 comments on commit 95f7ac7

Please sign in to comment.