Repository: tobymao/sqlglot

Issue:
Parser fails when using "interval" as name for a struct field 
This is a snippet that reproduces the problem:

```python
import sqlglot

working_sql = """
CREATE TABLE my_table (
  col STRUCT<`interval`: DOUBLE COMMENT 'aaa'>
)
"""

broken_sql = """
CREATE TABLE my_table (
  col STRUCT<interval: DOUBLE COMMENT 'aaa'>
)
"""

sqlglot.parse_one(working_sql, read="databricks")
print("If 'interval' is surrounded by backticks it works")

print("But if it is not then it breaks:")
sqlglot.parse_one(broken_sql, read="databricks")
```

As far as I can see (please correct me if I'm wrong), **even without backticks the parser should work**. Relevant links:
- https://docs.databricks.com/en/sql/language-manual/data-types/struct-type.html
- https://docs.databricks.com/en/sql/language-manual/sql-ref-identifiers.html
- https://docs.databricks.com/en/sql/language-manual/sql-ref-ansi-compliance.html#sql-keywords -> even if `spark.sql.ansi.enabled` is true, `interval` is not a reserved keyword

Thanks!


Discussion:

Patch:
diff --git a/sqlglot/dialects/mysql.py b/sqlglot/dialects/mysql.py
index ae73fd3f..554241d9 100644
--- a/sqlglot/dialects/mysql.py
+++ b/sqlglot/dialects/mysql.py
@@ -520,7 +520,7 @@ class MySQL(Dialect):
 
             return self.expression(exp.SetItem, this=charset, collate=collate, kind="NAMES")
 
-        def _parse_type(self) -> t.Optional[exp.Expression]:
+        def _parse_type(self, parse_interval: bool = True) -> t.Optional[exp.Expression]:
             # mysql binary is special and can work anywhere, even in order by operations
             # it operates like a no paren func
             if self._match(TokenType.BINARY, advance=False):
@@ -529,7 +529,7 @@ class MySQL(Dialect):
                 if isinstance(data_type, exp.DataType):
                     return self.expression(exp.Cast, this=self._parse_column(), to=data_type)
 
-            return super()._parse_type()
+            return super()._parse_type(parse_interval=parse_interval)
 
     class Generator(generator.Generator):
         LOCKING_READS_SUPPORTED = True
diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py
index 609a0830..37343332 100644
--- a/sqlglot/expressions.py
+++ b/sqlglot/expressions.py
@@ -752,12 +752,14 @@ class Expression(metaclass=_Expression):
             return klass(this=other, expression=this)
         return klass(this=this, expression=other)
 
-    def __getitem__(self, other: ExpOrStr | t.Tuple[ExpOrStr]):
+    def __getitem__(self, other: ExpOrStr | t.Tuple[ExpOrStr]) -> Bracket:
         return Bracket(
             this=self.copy(), expressions=[convert(e, copy=True) for e in ensure_list(other)]
         )
 
-    def __iter__(self):
+    def __iter__(self) -> t.Iterator:
+        if "expressions" in self.arg_types:
+            return iter(self.args.get("expressions") or [])
         # We define this because __getitem__ converts Expression into an iterable, which is
         # problematic because one can hit infinite loops if they do "for x in some_expr: ..."
         # See: https://peps.python.org/pep-0234/
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 0ce24e36..51dbcd34 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -3249,8 +3249,8 @@ class Parser(metaclass=_Parser):
             return self.UNARY_PARSERS[self._prev.token_type](self)
         return self._parse_at_time_zone(self._parse_type())
 
-    def _parse_type(self) -> t.Optional[exp.Expression]:
-        interval = self._parse_interval()
+    def _parse_type(self, parse_interval: bool = True) -> t.Optional[exp.Expression]:
+        interval = parse_interval and self._parse_interval()
         if interval:
             return interval
 
@@ -3426,7 +3426,7 @@ class Parser(metaclass=_Parser):
         return this
 
     def _parse_struct_types(self) -> t.Optional[exp.Expression]:
-        this = self._parse_type() or self._parse_id_var()
+        this = self._parse_type(parse_interval=False) or self._parse_id_var()
         self._match(TokenType.COLON)
         return self._parse_column_def(this)
 


Test patch:
diff --git a/tests/dialects/test_databricks.py b/tests/dialects/test_databricks.py
index d06e0f17..239b8510 100644
--- a/tests/dialects/test_databricks.py
+++ b/tests/dialects/test_databricks.py
@@ -5,6 +5,7 @@ class TestDatabricks(Validator):
     dialect = "databricks"
 
     def test_databricks(self):
+        self.validate_identity("CREATE TABLE t (c STRUCT<interval: DOUBLE COMMENT 'aaa'>)")
         self.validate_identity("SELECT CAST('11 23:4:0' AS INTERVAL DAY TO HOUR)")
         self.validate_identity("SELECT CAST('11 23:4:0' AS INTERVAL DAY TO MINUTE)")
         self.validate_identity("SELECT CAST('11 23:4:0' AS INTERVAL DAY TO SECOND)")
diff --git a/tests/test_expressions.py b/tests/test_expressions.py
index 9456a19c..b1b53601 100644
--- a/tests/test_expressions.py
+++ b/tests/test_expressions.py
@@ -15,8 +15,10 @@ class TestExpressions(unittest.TestCase):
         self.assertEqual(parse_one("x(1)").find(exp.Literal).depth, 1)
 
     def test_iter(self):
+        self.assertEqual([exp.Literal.number(1), exp.Literal.number(2)], list(parse_one("[1, 2]")))
+
         with self.assertRaises(TypeError):
-            for x in parse_one("SELECT 1"):
+            for x in parse_one("1"):
                 pass
 
     def test_eq(self):