nebius/SWE-bench-extra huggingface dataset:
Repository: andialbrecht/sqlparse

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

Comments:

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]
Repository: andialbrecht/sqlparse

Issue:
Support CONCURRENTLY keyword in CREATE INDEX statements
When parsing a statement like `CREATE INDEX CONCURRENTLY name ON ...`, "CONCURRENTLY name" is returned as a single identifier 

Comments:

Patch:
diff --git a/CHANGELOG b/CHANGELOG
index 5ffe811..b9b80a0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -8,6 +8,7 @@ Enhancements
 Bug Fixes
 
 * Fix some edge-cases when parsing invalid SQL statements.
+* Fix indentation of LIMIT (by romainr, pr321).
 
 Internal Changes
 
diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py
index 1fd07c1..d68b4ae 100644
--- a/sqlparse/keywords.py
+++ b/sqlparse/keywords.py
@@ -167,6 +167,7 @@ KEYWORDS = {
     'COMMIT': tokens.Keyword.DML,
     'COMMITTED': tokens.Keyword,
     'COMPLETION': tokens.Keyword,
+    'CONCURRENTLY': tokens.Keyword,
     'CONDITION_NUMBER': tokens.Keyword,
     'CONNECT': tokens.Keyword,
     'CONNECTION': tokens.Keyword,


Test patch:
diff --git a/tests/test_regressions.py b/tests/test_regressions.py
index cf88419..cc553c2 100644
--- a/tests/test_regressions.py
+++ b/tests/test_regressions.py
@@ -343,3 +343,16 @@ def test_issue315_utf8_by_default():
     if PY2:
         tformatted = tformatted.decode('utf-8')
     assert formatted == tformatted
+
+
+def test_issue322_concurrently_is_keyword():
+    s = 'CREATE INDEX CONCURRENTLY myindex ON mytable(col1);'
+    p = sqlparse.parse(s)[0]
+
+    assert len(p.tokens) == 12
+    assert p.tokens[0].ttype is T.Keyword.DDL  # CREATE
+    assert p.tokens[2].ttype is T.Keyword      # INDEX
+    assert p.tokens[4].ttype is T.Keyword      # CONCURRENTLY
+    assert p.tokens[4].value == 'CONCURRENTLY'
+    assert isinstance(p.tokens[6], sql.Identifier)
+    assert p.tokens[6].value == 'myindex'
Repository: andialbrecht/sqlparse

Issue:
strip_comments causing syntax error
If there is no space between comments and keyword, the output causes a syntax error. Here's an example:

```python
import sqlparse

sql='''select * from table1--this is a comment
inner join table2 on table1.id = table2.id--this is a comment
where table1.a=1'''

sqlparse.format(sql,strip_comments=True)
```
This gives the following as output:
`select * from table1inner join table2 on table1.id = table2.idwhere table1.a=1`

Comments:

Patch:
diff --git a/sqlparse/filters/others.py b/sqlparse/filters/others.py
index df4d861..b0bb898 100644
--- a/sqlparse/filters/others.py
+++ b/sqlparse/filters/others.py
@@ -26,6 +26,13 @@ class StripCommentsFilter(object):
             if (prev_ is None or next_ is None or
                     prev_.is_whitespace or prev_.match(T.Punctuation, '(') or
                     next_.is_whitespace or next_.match(T.Punctuation, ')')):
+                # Insert a whitespace to ensure the following SQL produces
+                # a valid SQL. For example:
+                #
+                # Before: select a--comment\nfrom foo
+                # After: select a from foo
+                if prev_ is not None and next_ is None:
+                    tlist.tokens.insert(tidx, sql.Token(T.Whitespace, ' '))
                 tlist.tokens.remove(token)
             else:
                 tlist.tokens[tidx] = sql.Token(T.Whitespace, ' ')


Test patch:
diff --git a/tests/test_format.py b/tests/test_format.py
index 72af62e..aff07c1 100644
--- a/tests/test_format.py
+++ b/tests/test_format.py
@@ -50,6 +50,19 @@ class TestFormat(object):
         sql = 'select-- foo\nfrom -- bar\nwhere'
         res = sqlparse.format(sql, strip_comments=True)
         assert res == 'select from where'
+        sql = 'select *-- statement starts here\n\nfrom foo'
+        res = sqlparse.format(sql, strip_comments=True)
+        assert res == 'select * from foo'
+        sql = 'select * from foo-- statement starts here\nwhere'
+        res = sqlparse.format(sql, strip_comments=True)
+        assert res == 'select * from foo where'
+        sql = 'select a-- statement starts here\nfrom foo'
+        res = sqlparse.format(sql, strip_comments=True)
+        assert res == 'select a from foo'
+        sql = '--comment\nselect a-- statement starts here\n' \
+              'from foo--comment\nf'
+        res = sqlparse.format(sql, strip_comments=True)
+        assert res == 'select a from foo f'
 
     def test_strip_comments_invalid_option(self):
         sql = 'select-- foo\nfrom -- bar\nwhere'
Repository: andialbrecht/sqlparse

Issue:
Space removed in the extract presto function after query formatting. 
```
sqlparse.format( "SELECT extract(HOUR from from_unixtime(hour_ts) AT TIME ZONE 'America/Los_Angeles') from table", reindent=True)
```
removes space between `from` and `from_unixtime(hour_ts` in the 0.3.1 version, works fine in 0.3.0

Related superset PR: https://github.com/apache/incubator-superset/pull/10165

Expected
```
SELECT extract(HOUR
               from from_unixtime(hour_ts) AT TIME ZONE 'America/Los_Angeles')
from table
```

Actual
```
SELECT extract(HOUR
               fromfrom_unixtime(hour_ts) AT TIME ZONE 'America/Los_Angeles')
from table
```

Comments:

Patch:
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py
index 175ae8e..2fb0a4c 100644
--- a/sqlparse/engine/grouping.py
+++ b/sqlparse/engine/grouping.py
@@ -91,13 +91,20 @@ def group_tzcasts(tlist):
     def match(token):
         return token.ttype == T.Keyword.TZCast
 
-    def valid(token):
+    def valid_prev(token):
         return token is not None
 
+    def valid_next(token):
+        return token is not None and (
+            token.is_whitespace
+            or token.match(T.Keyword, 'AS')
+            or token.match(*sql.TypedLiteral.M_CLOSE)
+        )
+
     def post(tlist, pidx, tidx, nidx):
         return pidx, nidx
 
-    _group(tlist, sql.Identifier, match, valid, valid, post)
+    _group(tlist, sql.Identifier, match, valid_prev, valid_next, post)
 
 
 def group_typed_literal(tlist):


Test patch:
diff --git a/tests/test_regressions.py b/tests/test_regressions.py
index 38d1840..4ffc69f 100644
--- a/tests/test_regressions.py
+++ b/tests/test_regressions.py
@@ -401,6 +401,15 @@ def test_issue489_tzcasts():
     assert p.tokens[-1].get_alias() == 'foo'
 
 
+def test_issue562_tzcasts():
+    # Test that whitespace between 'from' and 'bar' is retained
+    formatted = sqlparse.format(
+        'SELECT f(HOUR from bar AT TIME ZONE \'UTC\') from foo', reindent=True
+    )
+    assert formatted == \
+           'SELECT f(HOUR\n         from bar AT TIME ZONE \'UTC\')\nfrom foo'
+
+
 def test_as_in_parentheses_indents():
     # did raise NoneType has no attribute is_group in _process_parentheses
     formatted = sqlparse.format('(as foo)', reindent=True)
Repository: andialbrecht/sqlparse

Issue:
Dollar quoted strings (PostgreSQL) cannot follow an operator (e.g. `=$$Hello$$`) 
**Describe the bug**
Dollar quoted strings (e.g. PostgreSQL) are not properly detected, when there is an operator directly preceding the dollar quoted string (e.g `var=$$text$$`). While according to PostgreSQL docs ...

> A dollar-quoted string that follows a keyword or identifier must be separated from it by whitespace; otherwise the dollar quoting delimiter would be taken as part of the preceding identifier.

... this does not hold true for operators. i.e. `SET application_name=$$Hello$$;` is valid.

This seems to relate to 
https://github.com/andialbrecht/sqlparse/blob/f101546dafa921edfea5b3107731504665b758ea/sqlparse/keywords.py#L33
and the negative lookbehind ensuring that there's no non-whitespace character before the starting `$`. This potentially should be changed to
```
(r'((?<![\w\"\$])\$(?:[_A-ZÀ-Ü]\w*)?\$)[\s\S]*?\1', tokens.Literal)
```
which would filter out any keywords or identifiers.


**To Reproduce**

```python
sqlparse.split('''update test set a=$$test;test$$;''');
```

```
['update test set a=$$test;', 'test$$;']
```

**Expected behavior**

```
['update test set a=$$test;test$$;']
```

**Versions (please complete the following information):**
 - Python: 3.12.1
 - sqlparse: 0.4.4

**Additional context**
Add any other context about the problem here.


Comments:

Patch:
diff --git a/CHANGELOG b/CHANGELOG
index 0ede280..0b48e9f 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -14,6 +14,7 @@ Enhancements:
 Bug Fixes
 
 * Ignore dunder attributes when creating Tokens (issue672).
+* Allow operators to precede dollar-quoted strings (issue763).
 
 
 Release 0.4.4 (Apr 18, 2023)
diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py
index b45f3e0..d3794fd 100644
--- a/sqlparse/keywords.py
+++ b/sqlparse/keywords.py
@@ -30,7 +30,7 @@ SQL_REGEX = [
 
     (r"`(``|[^`])*`", tokens.Name),
     (r"´(´´|[^´])*´", tokens.Name),
-    (r'((?<!\S)\$(?:[_A-ZÀ-Ü]\w*)?\$)[\s\S]*?\1', tokens.Literal),
+    (r'((?<![\w\"\$])\$(?:[_A-ZÀ-Ü]\w*)?\$)[\s\S]*?\1', tokens.Literal),
 
     (r'\?', tokens.Name.Placeholder),
     (r'%(\(\w+\))?s', tokens.Name.Placeholder),


Test patch:
diff --git a/tests/test_parse.py b/tests/test_parse.py
index 5feef5a..6e4df7c 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -180,6 +180,14 @@ def test_psql_quotation_marks():
     $PROC_2$ LANGUAGE plpgsql;""")
     assert len(t) == 2
 
+    # operators are valid infront of dollar quoted strings
+    t = sqlparse.split("""UPDATE SET foo =$$bar;SELECT bar$$""")
+    assert len(t) == 1
+    
+    # identifiers must be separated by whitespace
+    t = sqlparse.split("""UPDATE SET foo TO$$bar;SELECT bar$$""")
+    assert len(t) == 2
+
 
 def test_double_precision_is_builtin():
     s = 'DOUBLE PRECISION'