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:

Patch:
diff --git a/sqlglot/generator.py b/sqlglot/generator.py
index cff7e049..58c0d3d3 100644
--- 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 @@ class Generator:
             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
index 40d49139..2d6a96b2 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -2589,12 +2589,12 @@ class Parser(metaclass=_Parser):
         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
index 40a3a040..9fd2b45c 100644
--- 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")