Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4467,16 +4467,18 @@ def _parse_aliased_expression() -> t.Optional[exp.Expression]:

value = self._parse_column()

if not self._match_pair(TokenType.IN, TokenType.L_PAREN):
self.raise_error("Expecting IN (")
if not self._match(TokenType.IN):
self.raise_error("Expecting IN")

if self._match(TokenType.ANY):
exprs: t.List[exp.Expression] = ensure_list(exp.PivotAny(this=self._parse_order()))
else:
exprs = self._parse_csv(_parse_aliased_expression)
if self._match(TokenType.L_PAREN):
if self._match(TokenType.ANY):
exprs: t.List[exp.Expression] = ensure_list(exp.PivotAny(this=self._parse_order()))
else:
exprs = self._parse_csv(_parse_aliased_expression)
self._match_r_paren()
return self.expression(exp.In, this=value, expressions=exprs)

self._match_r_paren()
return self.expression(exp.In, this=value, expressions=exprs)
return self.expression(exp.In, this=value, field=self._parse_id_var())

def _parse_pivot_aggregation(self) -> t.Optional[exp.Expression]:
func = self._parse_function()
Expand Down
2 changes: 2 additions & 0 deletions tests/dialects/test_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,8 @@ def test_duckdb(self):
# TODO: This is incorrect AST, DATE_PART creates a STRUCT of values but it's stored in 'year' arg
self.validate_identity("SELECT MAKE_DATE(DATE_PART(['year', 'month', 'day'], TODAY()))")

self.validate_identity("SELECT * FROM t PIVOT(SUM(y) FOR foo IN y_enum)")

def test_array_index(self):
with self.assertLogs(helper_logger) as cm:
self.validate_all(
Expand Down