Repository: tobymao/sqlglot
Pull request: Fix window parsing for ROWS BETWEEN without alias
fixes #931 

Problem statement:
Window frame fails to parse
```
In [27]: import sqlglot as sg

In [28]: sg.__version__
Out[28]: '10.4.3'

In [29]: sg.parse_one("SELECT avg(x) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t", read="duckdb")
...
ParseError: Expecting ). Line 1, Col: 26.
  SELECT avg(x) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t
```

Hints from issue discussion:

Commit message: Fix window parsing for ROWS BETWEEN without alias

Patch to review:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 4a01ed8a28..32d3173328 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -594,6 +594,8 @@ class Parser(metaclass=_Parser):
 
     TRANSACTION_KIND = {"DEFERRED", "IMMEDIATE", "EXCLUSIVE"}
 
+    WINDOW_ALIAS_TOKENS = ID_VAR_TOKENS - {TokenType.ROWS}
+
     # allows tables to have special tokens as prefixes
     TABLE_PREFIX_TOKENS: t.Set[TokenType] = set()
 
@@ -2676,7 +2678,7 @@ def _parse_window(
         if not self._match(TokenType.L_PAREN):
             return self.expression(exp.Window, this=this, alias=self._parse_id_var(False))
 
-        window_alias = self._parse_id_var(False)
+        window_alias = self._parse_id_var(any_token=False, tokens=self.WINDOW_ALIAS_TOKENS)
 
         partition = None
         if self._match(TokenType.PARTITION_BY):
diff --git a/tests/fixtures/identity.sql b/tests/fixtures/identity.sql
index 7f582214fe..50a5608528 100644
--- a/tests/fixtures/identity.sql
+++ b/tests/fixtures/identity.sql
@@ -426,6 +426,7 @@ SELECT SUM(x) OVER (PARTITION BY a RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT
 SELECT SUM(x) OVER (PARTITION BY a RANGE BETWEEN 1 AND 3)
 SELECT SUM(x) OVER (PARTITION BY a RANGE BETWEEN 1 FOLLOWING AND 3)
 SELECT SUM(x) OVER (PARTITION BY a RANGE BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING)
+SELECT AVG(x) OVER ( ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t
 SELECT LISTAGG(x) WITHIN GROUP (ORDER BY x) AS y
 SELECT LISTAGG(x) WITHIN GROUP (ORDER BY x DESC)
 SELECT SUM(x) FILTER(WHERE x > 1)


Code review comments:
diff_hunk: @@ -426,6 +426,7 @@ SELECT SUM(x) OVER (PARTITION BY a RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT
 SELECT SUM(x) OVER (PARTITION BY a RANGE BETWEEN 1 AND 3)
 SELECT SUM(x) OVER (PARTITION BY a RANGE BETWEEN 1 FOLLOWING AND 3)
 SELECT SUM(x) OVER (PARTITION BY a RANGE BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING)
+SELECT AVG(x) OVER ( ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM t
path: tests/fixtures/identity.sql
text: @user1:
this means the generator is not correct, it has a space in it

@author:
uploading the fix in a sec

@author:
done