Skip to content

Commit

Permalink
Fix: allow any identifier as name when parsing a struct field (#1573)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas authored May 9, 2023
1 parent e1713f3 commit fa0f3a1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2904,7 +2904,7 @@ def _parse_types(self, check_func: bool = False) -> t.Optional[exp.Expression]:
)

def _parse_struct_types(self) -> t.Optional[exp.Expression]:
this = self._parse_type()
this = self._parse_type() or self._parse_id_var()
self._match(TokenType.COLON)
return self._parse_column_def(this)

Expand Down
3 changes: 2 additions & 1 deletion tests/dialects/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ def test_bigquery(self):
self.validate_identity("SELECT AS VALUE STRUCT(1 AS a, 2 AS b)")
self.validate_identity("SELECT STRUCT<ARRAY<STRING>>(['2023-01-17'])")
self.validate_identity("SELECT * FROM q UNPIVOT(values FOR quarter IN (b, c))")
self.validate_identity("""CREATE TABLE x (a STRUCT<values ARRAY<INT64>>)""")
self.validate_identity("""CREATE TABLE x (a STRUCT<b STRING OPTIONS (description='b')>)""")
self.validate_identity(
"""CREATE TABLE x (a STRING OPTIONS (description='x')) OPTIONS (table_expiration_days=1)"""
)
self.validate_identity("""CREATE TABLE x (a STRUCT<b STRING OPTIONS (description='b')>)""")
self.validate_identity(
"SELECT * FROM (SELECT * FROM `t`) AS a UNPIVOT((c) FOR c_name IN (v1, v2))"
)
Expand Down

0 comments on commit fa0f3a1

Please sign in to comment.