Repository: tobymao/sqlglot

Issue:
Previously passing ClickHouse parsing now fails
```
In [1]: import sqlglot as sg

In [2]: sg.__version__
Out[2]: '11.5.5'

In [3]: sg.parse_one("select interval t.days day from t", read="clickhouse")
...
ParseError: Invalid expression / Unexpected token. Line 1, Col: 18.
  select interval t.days day from t
```

This is valid syntax in ClickHouse:

```
6c78ea98b052 :) select * from t;

SELECT *
FROM t

Query id: 48af9fec-cc98-4f8d-bdd5-c4d202efc16c

┌─days─┐
│    1 │
│    2 │
└──────┘

2 rows in set. Elapsed: 0.001 sec.

6c78ea98b052 :) select interval t.days day from t;

SELECT toIntervalDay(t.days)
FROM t

Query id: a4307884-dc25-45e7-b903-eb8046188e22

┌─toIntervalDay(days)─┐
│                   1 │
│                   2 │
└─────────────────────┘

2 rows in set. Elapsed: 0.001 sec.
```


Discussion:
Will take a look soon, thanks for reporting this.

Resolving patch:
diff --git a/sqlglot/generator.py b/sqlglot/generator.py
--- a/sqlglot/generator.py
+++ b/sqlglot/generator.py
@@ -212,6 +212,8 @@ class Generator:
 
     WITH_SEPARATED_COMMENTS = (exp.Select, exp.From, exp.Where, exp.With)
 
+    UNWRAPPED_INTERVAL_VALUES = (exp.Literal, exp.Paren, exp.Column)
+
     SENTINEL_LINE_BREAK = "__SQLGLOT__LB__"
 
     __slots__ = (
@@ -1704,15 +1706,10 @@ def interval_sql(self, expression: exp.Interval) -> str:
             this = expression.this.name if expression.this else ""
             return f"INTERVAL '{this}{unit}'"
 
-        this = expression.this
+        this = self.sql(expression, "this")
         if this:
-            this = (
-                f" {this}"
-                if isinstance(this, exp.Literal) or isinstance(this, exp.Paren)
-                else f" ({this})"
-            )
-        else:
-            this = ""
+            unwrapped = isinstance(expression.this, self.UNWRAPPED_INTERVAL_VALUES)
+            this = f" {this}" if unwrapped else f" ({this})"
 
         return f"INTERVAL{this}{unit}"
 
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -2589,12 +2589,12 @@ def _parse_interval(self) -> t.Optional[exp.Expression]:
         if not self._match(TokenType.INTERVAL):
             return None
 
-        this = self._parse_primary()
+        this = self._parse_primary() or self._parse_column()
         unit = self._parse_function() or self._parse_var()
 
         # Most dialects support, e.g., the form INTERVAL '5' day, thus we try to parse
         # each INTERVAL expression into this canonical form so it's easy to transpile
-        if this:
+        if this and isinstance(this, exp.Literal):
             if this.is_number:
                 this = exp.Literal.string(this.name)
 


Test patch:
diff --git a/tests/dialects/test_clickhouse.py b/tests/dialects/test_clickhouse.py
--- a/tests/dialects/test_clickhouse.py
+++ b/tests/dialects/test_clickhouse.py
@@ -5,6 +5,7 @@ class TestClickhouse(Validator):
     dialect = "clickhouse"
 
     def test_clickhouse(self):
+        self.validate_identity("SELECT INTERVAL t.days day")
         self.validate_identity("SELECT match('abc', '([a-z]+)')")
         self.validate_identity("dictGet(x, 'y')")
         self.validate_identity("SELECT * FROM x FINAL")