Skip to content

Commit

Permalink
Fix: values inner alias snowflake closes #1768
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Jun 13, 2023
1 parent 35d960a commit 5955b9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2373,11 +2373,14 @@ def _parse_derived_table_values(self) -> t.Optional[exp.Values]:
return None

expressions = self._parse_csv(self._parse_value)
alias = self._parse_table_alias()

if is_derived:
self._match_r_paren()

return self.expression(exp.Values, expressions=expressions, alias=self._parse_table_alias())
return self.expression(
exp.Values, expressions=expressions, alias=alias or self._parse_table_alias()
)

def _parse_table_sample(self, as_modifier: bool = False) -> t.Optional[exp.TableSample]:
if not self._match(TokenType.TABLE_SAMPLE) and not (
Expand Down
4 changes: 4 additions & 0 deletions tests/dialects/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def test_snowflake(self):
self.validate_identity("SELECT CONVERT_TIMEZONE('UTC', 'America/Los_Angeles', col)")

self.validate_all("CAST(x AS CHAR VARYING)", write={"snowflake": "CAST(x AS VARCHAR)"})
self.validate_all(
"SELECT * FROM (VALUES (0) foo(bar))",
write={"snowflake": "SELECT * FROM (VALUES (0)) AS foo(bar)"},
)
self.validate_all("CAST(x AS CHARACTER VARYING)", write={"snowflake": "CAST(x AS VARCHAR)"})
self.validate_all("CAST(x AS NCHAR VARYING)", write={"snowflake": "CAST(x AS VARCHAR)"})
self.validate_all(
Expand Down

0 comments on commit 5955b9e

Please sign in to comment.