Repository: edgedb/edgedb

Issue:
InternalServerError: operator is not unique: date `-` date_duration_t (from range)
- EdgeDB Version: 4.5

Steps to Reproduce:

```edgeql
with
  period := range(
    <cal::local_date>"2024-01-01",
    <cal::local_date>"2025-01-05",
    inc_upper := true
  ),
  upper := range_get_upper(period)

select upper - <cal::date_duration>"1 day"
```
```
InternalServerError: operator is not unique: date `-` date_duration_t
```


Discussion:
FWIW I think the `range_get_upper` should give me the 5th, not the 6th anyways.
```edgeql
select range_get_upper(range(1.5, 7.5, inc_upper := true)); # => 7.5

select range_get_upper(range(
    <cal::local_date>"2024-01-01",
    <cal::local_date>"2025-01-05",
    inc_upper := true
)) # => "2025-01-06"
```
"The 6th? I just put in the 5th."

I know this differs from `datetime` logic, and I stand beside that.
I also know that this would be a breaking change, so I doubt it will be changed.
I was able to work around this by casting to str and back.
```edgeql
<cal::local_date><str>range_get_upper(period) - <cal::date_duration>"1 day"
```

Resolving patch:
diff --git a/edb/buildmeta.py b/edb/buildmeta.py
--- a/edb/buildmeta.py
+++ b/edb/buildmeta.py
@@ -55,7 +55,7 @@
 
 
 # Increment this whenever the database layout or stdlib changes.
-EDGEDB_CATALOG_VERSION = 2024_04_18_00_01
+EDGEDB_CATALOG_VERSION = 2024_04_25_00_00
 EDGEDB_MAJOR_VERSION = 6
 
 


Test patch:
diff --git a/tests/test_edgeql_expressions.py b/tests/test_edgeql_expressions.py
--- a/tests/test_edgeql_expressions.py
+++ b/tests/test_edgeql_expressions.py
@@ -5425,6 +5425,48 @@ async def test_edgeql_expr_range_17(self):
             [],
         )
 
+        # check that return type of sql is correct
+        # https://github.com/edgedb/edgedb/issues/6786
+        await self.assert_query_result(
+            f'''select <str>(range_get_upper(
+                    range(
+                        <cal::local_datetime>'2024-01-11T00:00:00',
+                        <cal::local_datetime>'2025-01-11T00:00:00'
+                    )
+                ) - <cal::date_duration>"1 day");''',
+            ['2025-01-10T00:00:00'],
+        )
+
+        await self.assert_query_result(
+            f'''select <str>(range_get_lower(
+                    range(
+                        <cal::local_datetime>'2024-01-11T00:00:00',
+                        <cal::local_datetime>'2025-01-11T00:00:00'
+                    )
+                ) - <cal::date_duration>"1 day");''',
+            ['2024-01-10T00:00:00'],
+        )
+
+        await self.assert_query_result(
+            f'''select <str>(range_get_upper(
+                    multirange([range(
+                        <cal::local_datetime>'2024-01-11T00:00:00',
+                        <cal::local_datetime>'2025-01-11T00:00:00'
+                    )])
+                ) - <cal::date_duration>"1 day");''',
+            ['2025-01-10T00:00:00'],
+        )
+
+        await self.assert_query_result(
+            f'''select <str>(range_get_lower(
+                    multirange([range(
+                        <cal::local_datetime>'2024-01-11T00:00:00',
+                        <cal::local_datetime>'2025-01-11T00:00:00'
+                    )])
+                ) - <cal::date_duration>"1 day");''',
+            ['2024-01-10T00:00:00'],
+        )
+
     async def test_edgeql_expr_range_18(self):
         # Test bound for datetime ranges and multiranges.
         await self.assert_query_result(
@@ -5887,6 +5929,48 @@ async def test_edgeql_expr_range_24(self):
             [],
         )
 
+        # check that return type of sql is correct
+        # https://github.com/edgedb/edgedb/issues/6786
+        await self.assert_query_result(
+            f'''select <str>(range_get_upper(
+                    range(
+                        <cal::local_date>'2024-01-11',
+                        <cal::local_date>'2025-01-11'
+                    )
+                ) - <cal::date_duration>"1 day");''',
+            ['2025-01-10'],
+        )
+
+        await self.assert_query_result(
+            f'''select <str>(range_get_lower(
+                    range(
+                        <cal::local_date>'2024-01-11',
+                        <cal::local_date>'2025-01-11'
+                    )
+                ) - <cal::date_duration>"1 day");''',
+            ['2024-01-10'],
+        )
+
+        await self.assert_query_result(
+            f'''select <str>(range_get_upper(
+                    multirange([range(
+                        <cal::local_date>'2024-01-11',
+                        <cal::local_date>'2025-01-11'
+                    )])
+                ) - <cal::date_duration>"1 day");''',
+            ['2025-01-10'],
+        )
+
+        await self.assert_query_result(
+            f'''select <str>(range_get_lower(
+                    multirange([range(
+                        <cal::local_date>'2024-01-11',
+                        <cal::local_date>'2025-01-11'
+                    )])
+                ) - <cal::date_duration>"1 day");''',
+            ['2024-01-10'],
+        )
+
     async def test_edgeql_expr_range_25(self):
         # Test bound for date ranges and multiranges.
         await self.assert_query_result(