Skip to content

Commit 9ddae4d

Browse files
authored
fix(duckdb): support IN with no paren (#6409)
1 parent 11354cc commit 9ddae4d

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

sqlglot/parser.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4467,16 +4467,18 @@ def _parse_aliased_expression() -> t.Optional[exp.Expression]:
44674467

44684468
value = self._parse_column()
44694469

4470-
if not self._match_pair(TokenType.IN, TokenType.L_PAREN):
4471-
self.raise_error("Expecting IN (")
4470+
if not self._match(TokenType.IN):
4471+
self.raise_error("Expecting IN")
44724472

4473-
if self._match(TokenType.ANY):
4474-
exprs: t.List[exp.Expression] = ensure_list(exp.PivotAny(this=self._parse_order()))
4475-
else:
4476-
exprs = self._parse_csv(_parse_aliased_expression)
4473+
if self._match(TokenType.L_PAREN):
4474+
if self._match(TokenType.ANY):
4475+
exprs: t.List[exp.Expression] = ensure_list(exp.PivotAny(this=self._parse_order()))
4476+
else:
4477+
exprs = self._parse_csv(_parse_aliased_expression)
4478+
self._match_r_paren()
4479+
return self.expression(exp.In, this=value, expressions=exprs)
44774480

4478-
self._match_r_paren()
4479-
return self.expression(exp.In, this=value, expressions=exprs)
4481+
return self.expression(exp.In, this=value, field=self._parse_id_var())
44804482

44814483
def _parse_pivot_aggregation(self) -> t.Optional[exp.Expression]:
44824484
func = self._parse_function()

tests/dialects/test_duckdb.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,8 @@ def test_duckdb(self):
12441244
# TODO: This is incorrect AST, DATE_PART creates a STRUCT of values but it's stored in 'year' arg
12451245
self.validate_identity("SELECT MAKE_DATE(DATE_PART(['year', 'month', 'day'], TODAY()))")
12461246

1247+
self.validate_identity("SELECT * FROM t PIVOT(SUM(y) FOR foo IN y_enum)")
1248+
12471249
def test_array_index(self):
12481250
with self.assertLogs(helper_logger) as cm:
12491251
self.validate_all(

0 commit comments

Comments
 (0)