Repository: tobymao/sqlglot

Issue:
Redshift Dialect - GROUP BY clause causes parsing error although query is valid
**Fully reproducible code snippet**
``` CREATE OR REPLACE VIEW my_view AS
SELECT id,
       AVG(average_metric1)                   AS m1,
       AVG(average_metric2)                   AS m2
FROM table
GROUP BY id
WITH NO SCHEMA BINDING;
```
This query causes the following parsing error when running the below code, although query is valid in **Redshift**:

`parse(query, read="redshift")`

![image](https://github.com/tobymao/sqlglot/assets/19167079/f0552550-3ddf-4ecd-8cca-7306c4a8d069)

Removing `GROUP BY id` solves the parsing issue, however is not a valid Redshift query in that case.


**Official Documentation**
Please include links to official SQL documentation related to your issue.


Discussion:

Patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 8de76caf..e3409977 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -2952,6 +2952,7 @@ class Parser(metaclass=_Parser):
             cube = None
             totals = None
 
+            index = self._index
             with_ = self._match(TokenType.WITH)
             if self._match(TokenType.ROLLUP):
                 rollup = with_ or self._parse_wrapped_csv(self._parse_column)
@@ -2966,6 +2967,8 @@ class Parser(metaclass=_Parser):
                 elements["totals"] = True  # type: ignore
 
             if not (grouping_sets or rollup or cube or totals):
+                if with_:
+                    self._retreat(index)
                 break
 
         return self.expression(exp.Group, **elements)  # type: ignore


Test patch:
diff --git a/tests/dialects/test_redshift.py b/tests/dialects/test_redshift.py
index f182febf..83986e59 100644
--- a/tests/dialects/test_redshift.py
+++ b/tests/dialects/test_redshift.py
@@ -6,6 +6,9 @@ class TestRedshift(Validator):
     dialect = "redshift"
 
     def test_redshift(self):
+        self.validate_identity(
+            "CREATE OR REPLACE VIEW v1 AS SELECT id, AVG(average_metric1) AS m1, AVG(average_metric2) AS m2 FROM t GROUP BY id WITH NO SCHEMA BINDING"
+        )
         self.validate_all(
             "SELECT APPROXIMATE COUNT(DISTINCT y)",
             read={