This happened only for the binary format, not the text format.
- Fix wrong escaping of unprintable chars in COPY (nonetheless correctly
interpreted by PostgreSQL).
- Restore the connection to usable state after an error in `~Cursor.stream()`.
+- Raise `DataError` instead of `OverflowError` loading binary intervals
+ out-of-range.
Current release
elif months < 0:
years, months = divmod(-months, 12)
days = days - 30 * months - 365 * years
- return timedelta(days=days, microseconds=micros)
+
+ try:
+ return timedelta(days=days, microseconds=micros)
+ except OverflowError as e:
+ raise DataError(f"can't parse interval: {e}") from None
def _get_datestyle(conn: Optional["BaseConnection[Any]"]) -> bytes:
usdays = -usdays
us = -us
- return cdt.timedelta_new(days + usdays, ussecs, us)
+ try:
+ return cdt.timedelta_new(days + usdays, ussecs, us)
+ except OverflowError as ex:
+ raise e.DataError(f"can't parse interval: {ex}")
cdef const char *_parse_date_values(
cur.execute(f"select '{expr}'::interval")
assert cur.fetchone()[0] == as_td(val)
+ @pytest.mark.parametrize("fmt_out", pq.Format)
@pytest.mark.parametrize("val", ["min", "max"])
- def test_load_interval_overflow(self, conn, val):
- cur = conn.cursor()
+ def test_load_interval_overflow(self, conn, val, fmt_out):
+ cur = conn.cursor(binary=fmt_out)
cur.execute(
"select %s + %s * '1s'::interval",
(as_td(val), -1 if val == "min" else 1),