Skip to content

Commit 1b6076b

Browse files
committed
Fix!: wrap connectives generated due to transpiling LIKE ANY closes #6493
1 parent ef130f1 commit 1b6076b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

sqlglot/generator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3841,6 +3841,10 @@ def _like_sql(self, expression: exp.Like | exp.ILike) -> str:
38413841
for expr in exprs[1:]:
38423842
like_expr = connective(like_expr, exp_class(this=this, expression=expr))
38433843

3844+
parent = expression.parent
3845+
if not isinstance(parent, type(like_expr)) and isinstance(parent, exp.Condition):
3846+
like_expr = exp.paren(like_expr, copy=False)
3847+
38443848
return self.sql(like_expr)
38453849

38463850
return self.binary(expression, op)

tests/dialects/test_duckdb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ def test_duckdb(self):
4444
"STRUCT(k TEXT, v STRUCT(v_str TEXT, v_int INT, v_int_arr INT[]))[]",
4545
)
4646

47+
self.validate_all(
48+
"(c LIKE 'a' OR c LIKE 'b') AND other_cond",
49+
read={
50+
"databricks": "c LIKE ANY ('a', 'b') AND other_cond",
51+
},
52+
)
4753
self.validate_all(
4854
"SELECT FIRST_VALUE(c IGNORE NULLS) OVER (PARTITION BY gb ORDER BY ob) FROM t",
4955
write={

0 commit comments

Comments
 (0)