]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix(c): fix loading of intervals with days and months or years
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 19 Sep 2023 19:07:20 +0000 (21:07 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 19 Sep 2023 20:23:28 +0000 (22:23 +0200)
Close #643.

docs/news.rst
psycopg_c/psycopg_c/types/datetime.pyx
tests/types/test_datetime.py

index f8e4834df98c8ce1715051783ff5e99985a467eb..63290f460c6fa21f1733be1d1dd4c9dc8ef10ead 100644 (file)
@@ -16,6 +16,7 @@ Psycopg 3.1.11 (unreleased)
 - Avoid caching the parsing results of large queries to avoid excessive memory
   usage (:ticket:`#628`).
 - Fix integer overflow in C/binary extension with OID > 2^31 (:ticket:`#630`).
+- Fix loading of intervals with days and months or years (:ticket:`#643`).
 - Fix building on Solaris and derivatives (:ticket:`#632`).
 - Fix possible lack of critical section guard in async
   `~AsyncCursor.executemany()`.
index 3b6fd1f18406b35faa53336efb00b0f150894909..1dd859816898838118e18f6fce87c7d5faf35876 100644 (file)
@@ -879,11 +879,11 @@ cdef class IntervalLoader(CLoader):
                 val = -val
 
             if ptr[1] == b'y':
-                days = 365 * val
+                days += 365 * val
             elif ptr[1] == b'm':
-                days = 30 * val
+                days += 30 * val
             elif ptr[1] == b'd':
-                days = val
+                days += val
             else:
                 s = bytes(data).decode("utf8", "replace")
                 raise e.DataError(f"can't parse interval {s!r}")
index 11fe4932cad2560c89bb520d591fdf9268a8e93f..c89d364d9578c457ddbd57195b3f26be5e64803a 100644 (file)
@@ -688,6 +688,8 @@ class TestInterval:
             ("-30d", "-1 month"),
             ("60d", "2 month"),
             ("-90d", "-3 month"),
+            ("186d", "6 mons 6 days"),
+            ("736d", "2 years 6 days"),
         ],
     )
     @pytest.mark.parametrize("fmt_out", pq.Format)