Repository: andialbrecht/sqlparse

Issue:
Functions are not grouped into a Comparison
I.e. `foo = DATE(bar.baz)` is not grouped.

Discussion:

Patch:
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py
index 4e45f65..68960d5 100644
--- a/sqlparse/engine/grouping.py
+++ b/sqlparse/engine/grouping.py
@@ -135,7 +135,8 @@ def group_comparison(tlist):
                                 T.Name, T.Number, T.Number.Float,
                                 T.Number.Integer, T.Literal,
                                 T.Literal.Number.Integer, T.Name.Placeholder)
-                or isinstance(token, (sql.Identifier, sql.Parenthesis))
+                or isinstance(token, (sql.Identifier, sql.Parenthesis,
+                                      sql.Function))
                 or (token.ttype is T.Keyword
                     and token.value.upper() in ['NULL', ]))
     _group_left_right(tlist, T.Operator.Comparison, None, sql.Comparison,


Test patch:
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index e846176..a6c4028 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -325,6 +325,29 @@ def test_comparison_with_strings():  # issue148
     assert p.tokens[0].right.ttype == T.String.Single
 
 
+def test_comparison_with_functions():  # issue230
+    p = sqlparse.parse('foo = DATE(bar.baz)')[0]
+    assert len(p.tokens) == 1
+    assert isinstance(p.tokens[0], sql.Comparison)
+    assert len(p.tokens[0].tokens) == 5
+    assert p.tokens[0].left.value == 'foo'
+    assert p.tokens[0].right.value == 'DATE(bar.baz)'
+    
+    p = sqlparse.parse('DATE(foo.bar) = DATE(bar.baz)')[0]
+    assert len(p.tokens) == 1
+    assert isinstance(p.tokens[0], sql.Comparison)
+    assert len(p.tokens[0].tokens) == 5
+    assert p.tokens[0].left.value == 'DATE(foo.bar)'
+    assert p.tokens[0].right.value == 'DATE(bar.baz)'
+    
+    p = sqlparse.parse('DATE(foo.bar) = bar.baz')[0]
+    assert len(p.tokens) == 1
+    assert isinstance(p.tokens[0], sql.Comparison)
+    assert len(p.tokens[0].tokens) == 5
+    assert p.tokens[0].left.value == 'DATE(foo.bar)'
+    assert p.tokens[0].right.value == 'bar.baz'
+
+
 @pytest.mark.parametrize('start', ['FOR', 'FOREACH'])
 def test_forloops(start):
     p = sqlparse.parse('%s foo in bar LOOP foobar END LOOP' % start)[0]