Skip to content

Commit

Permalink
Fix(optimizer): handle edge case in DATE_TRUNC simplification (#2368)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas authored Oct 3, 2023
1 parent f777155 commit 0d1e674
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sqlglot/optimizer/simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def simplify_datetrunc_predicate(expression: exp.Expression) -> exp.Expression:
l = expression.this
rs = expression.expressions

if all(_is_datetrunc_predicate(l, r) for r in rs):
if rs and all(_is_datetrunc_predicate(l, r) for r in rs):
unit = l.unit.name.lower()

ranges = []
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/optimizer/simplify.sql
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ CONCAT('a', x, y, 'bc');
'a' || 'b' || x;
CONCAT('ab', x);

CONCAT(a, b) IN (SELECT * FROM foo WHERE cond);
CONCAT(a, b) IN (SELECT * FROM foo WHERE cond);

--------------------------------------
-- DATE_TRUNC
--------------------------------------
Expand Down

0 comments on commit 0d1e674

Please sign in to comment.