Repository: tobymao/sqlglot

Issue:
interval parsing for postgresql
Hi! I have some problems with parsing postgresql statements that has more that one date units in intervals...
lib version 25.34.0
```python3
import sqlglot

sql = """
select *
from table
where 
    some_column >= (current_date + interval '1 day 1 hour')
    and some_another_column is True;
"""

parsed = sqlglot.parse_one(sql, dialect="postgres")
```
This works fine and we have
```
expression=Paren(
    this=Add(
        this=CurrentDate(),
        expression=Interval(this=Literal(this=1 day 1 hour, is_string=True))
    )
)
```
But if we drop brackets in where statement
```sql
select *
from table
where 
    some_column >= current_date + interval '1 day 1 hour'
    and some_another_column is True;
```
parser throw exception `sqlglot.errors.ParseError: Invalid expression / Unexpected token. Line 6, Col: 24.`
```
expression=Add(
    this=CurrentDate(),
    expression=Interval(
        this=Literal(this=1 day 1 hour, is_string=True),
        unit=Var(this=AND)
    )
)
```

**Official Documentation**
https://www.postgresql.org/docs/current/functions-datetime.html

Discussion:
@ankur334: Shall I check this?@fuglaeff: One more example that has the expected result, but strange (for postgres) syntax
```sql
select *
from table
where 
    some_column >= current_date + (interval '1 day 1 hour')
    and some_another_column is True;
```@VaggelisD: @ankur334 Feel free to take a stab at it if that's what you mean, thank you!@ankur334: Sure @georgesittas and @VaggelisD I am looking into this. I hope to solve it. I will inform the team if I get stuck somewhere@VaggelisD: Really appreciate it @ankur334, don't hesitate to ping us on slack for quicker iterations.

Solution patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index fbbc8f14d4..48b59ecfaa 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -4620,14 +4620,14 @@ def _parse_interval(self, match_interval: bool = True) -> t.Optional[exp.Add | e
             this = exp.Literal.string(this.to_py())
         elif this and this.is_string:
             parts = exp.INTERVAL_STRING_RE.findall(this.name)
-            if len(parts) == 1:
-                if unit:
-                    # Unconsume the eagerly-parsed unit, since the real unit was part of the string
-                    self._retreat(self._index - 1)
+            if parts and unit:
+                # Unconsume the eagerly-parsed unit, since the real unit was part of the string
+                unit = None
+                self._retreat(self._index - 1)
 
+            if len(parts) == 1:
                 this = exp.Literal.string(parts[0][0])
                 unit = self.expression(exp.Var, this=parts[0][1].upper())
-
         if self.INTERVAL_SPANS and self._match_text_seq("TO"):
             unit = self.expression(
                 exp.IntervalSpan, this=unit, expression=self._parse_var(any_token=True, upper=True)


Test patch:
diff --git a/tests/dialects/test_postgres.py b/tests/dialects/test_postgres.py
index 204151ed38..acdb2d4a83 100644
--- a/tests/dialects/test_postgres.py
+++ b/tests/dialects/test_postgres.py
@@ -71,6 +71,9 @@ def test_postgres(self):
         self.validate_identity("EXEC AS myfunc @id = 123", check_command_warning=True)
         self.validate_identity("SELECT CURRENT_USER")
         self.validate_identity("SELECT * FROM ONLY t1")
+        self.validate_identity(
+            "SELECT * FROM t WHERE some_column >= CURRENT_DATE + INTERVAL '1 day 1 hour' AND some_another_column IS TRUE"
+        )
         self.validate_identity(
             """UPDATE "x" SET "y" = CAST('0 days 60.000000 seconds' AS INTERVAL) WHERE "x"."id" IN (2, 3)"""
         )