From 9004b7badc1c4442351d718a7cea2e6f4040393c Mon Sep 17 00:00:00 2001 From: firebladed <34522909+firebladed@users.noreply.github.com> Date: Wed, 3 Jun 2026 22:29:32 +0100 Subject: [PATCH 1/6] Add Infinity checking based on descriptions in https://www.postgresql.org/message-id/E1r2rB1-005PHm-UL%40gemulon.postgresql.org --- sqlx-postgres/src/types/interval.rs | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/sqlx-postgres/src/types/interval.rs b/sqlx-postgres/src/types/interval.rs index 0266ad4b69..895cd203da 100644 --- a/sqlx-postgres/src/types/interval.rs +++ b/sqlx-postgres/src/types/interval.rs @@ -17,6 +17,28 @@ pub struct PgInterval { pub microseconds: i64, } +impl PgInterval { + pub const INFINITY: Self = Self { + months: i32::MAX, + days: i32::MAX, + microseconds: i64::MAX, + }; + + pub const NEG_INFINITY: Self = Self { + months: i32::MIN, + days: i32::MIN, + microseconds: i64::MIN, + }; + + pub fn is_infinite(&self) -> bool { + *self == Self::INFINITY || *self == Self::NEG_INFINITY + } + + pub fn is_positive_infinity(&self) -> bool { + *self == Self::INFINITY + } +} + impl Type for PgInterval { fn type_info() -> PgTypeInfo { PgTypeInfo::INTERVAL @@ -330,6 +352,23 @@ fn test_pginterval_std() { assert!(PgInterval::try_from(std::time::Duration::from_secs(20_000_000_000_000)).is_err()); } +#[test] +fn test_pginterval_infinity() { + assert!(PgInterval::INFINITY.is_infinite()); + assert!(PgInterval::NEG_INFINITY.is_infinite()); + assert!(PgInterval::INFINITY.is_positive_infinity()); + assert!(!PgInterval::NEG_INFINITY.is_positive_infinity()); + assert!(!PgInterval::default().is_infinite()); + + // verify sentinel values match what PostgreSQL expects + assert_eq!(PgInterval::INFINITY.microseconds, i64::MAX); + assert_eq!(PgInterval::INFINITY.days, i32::MAX); + assert_eq!(PgInterval::INFINITY.months, i32::MAX); + assert_eq!(PgInterval::NEG_INFINITY.microseconds, i64::MIN); + assert_eq!(PgInterval::NEG_INFINITY.days, i32::MIN); + assert_eq!(PgInterval::NEG_INFINITY.months, i32::MIN); +} + #[test] #[cfg(feature = "chrono")] fn test_pginterval_chrono() { From fd219429d5bd1c54f5097f4d31e9c063bb4e272c Mon Sep 17 00:00:00 2001 From: firebladed <34522909+firebladed@users.noreply.github.com> Date: Fri, 5 Jun 2026 16:07:09 +0100 Subject: [PATCH 2/6] Add is_negative_infinity function --- sqlx-postgres/src/types/interval.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sqlx-postgres/src/types/interval.rs b/sqlx-postgres/src/types/interval.rs index 895cd203da..bec46107f2 100644 --- a/sqlx-postgres/src/types/interval.rs +++ b/sqlx-postgres/src/types/interval.rs @@ -37,6 +37,10 @@ impl PgInterval { pub fn is_positive_infinity(&self) -> bool { *self == Self::INFINITY } + + pub fn is_negative_infinity(&self) -> bool { + *self == Self::NEG_INFINITY + } } impl Type for PgInterval { @@ -358,9 +362,11 @@ fn test_pginterval_infinity() { assert!(PgInterval::NEG_INFINITY.is_infinite()); assert!(PgInterval::INFINITY.is_positive_infinity()); assert!(!PgInterval::NEG_INFINITY.is_positive_infinity()); + assert!(!PgInterval::INFINITY.is_negative_infinity()); + assert!(PgInterval::NEG_INFINITY.is_negative_infinity()); assert!(!PgInterval::default().is_infinite()); - // verify sentinel values match what PostgreSQL expects + // verify values match what PostgreSQL expects assert_eq!(PgInterval::INFINITY.microseconds, i64::MAX); assert_eq!(PgInterval::INFINITY.days, i32::MAX); assert_eq!(PgInterval::INFINITY.months, i32::MAX); From 83202dd5500e7cf4b9e95e88cc3382baf4cfa671 Mon Sep 17 00:00:00 2001 From: firebladed <34522909+firebladed@users.noreply.github.com> Date: Sat, 6 Jun 2026 00:24:59 +0100 Subject: [PATCH 3/6] fix whitespace --- sqlx-postgres/src/types/interval.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlx-postgres/src/types/interval.rs b/sqlx-postgres/src/types/interval.rs index bec46107f2..baa26af102 100644 --- a/sqlx-postgres/src/types/interval.rs +++ b/sqlx-postgres/src/types/interval.rs @@ -363,7 +363,7 @@ fn test_pginterval_infinity() { assert!(PgInterval::INFINITY.is_positive_infinity()); assert!(!PgInterval::NEG_INFINITY.is_positive_infinity()); assert!(!PgInterval::INFINITY.is_negative_infinity()); - assert!(PgInterval::NEG_INFINITY.is_negative_infinity()); + assert!(PgInterval::NEG_INFINITY.is_negative_infinity()); assert!(!PgInterval::default().is_infinite()); // verify values match what PostgreSQL expects From 7bd327bda0a139d8b0bcb485fe830c4d88e79031 Mon Sep 17 00:00:00 2001 From: firebladed <34522909+firebladed@users.noreply.github.com> Date: Fri, 12 Jun 2026 00:58:24 +0100 Subject: [PATCH 4/6] added "INTERVAL 'infinity'" and "INTERVAL '-infinity'" tests --- tests/postgres/types.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/postgres/types.rs b/tests/postgres/types.rs index 145e46f12b..05b52b713b 100644 --- a/tests/postgres/types.rs +++ b/tests/postgres/types.rs @@ -665,6 +665,11 @@ test_prepared_type!(interval( days: 0, microseconds: (3 * 3_600 + 10 * 60 + 20) * 1_000_000 + 116100 }, + "INTERVAL 'infinity'" + == PgInterval::INFINITY, + "INTERVAL '-infinity'" + == PgInterval::NEG_INFINITY, + )); test_prepared_type!(money(Postgres, "123.45::money" == PgMoney(12345))); From d328b37dc44c3fdb5dc2a57766fc4549f463e3bc Mon Sep 17 00:00:00 2001 From: firebladed <34522909+firebladed@users.noreply.github.com> Date: Fri, 12 Jun 2026 01:00:33 +0100 Subject: [PATCH 5/6] fix whitespace --- tests/postgres/types.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/postgres/types.rs b/tests/postgres/types.rs index 05b52b713b..2a9576154f 100644 --- a/tests/postgres/types.rs +++ b/tests/postgres/types.rs @@ -668,8 +668,7 @@ test_prepared_type!(interval( "INTERVAL 'infinity'" == PgInterval::INFINITY, "INTERVAL '-infinity'" - == PgInterval::NEG_INFINITY, - + == PgInterval::NEG_INFINITY, )); test_prepared_type!(money(Postgres, "123.45::money" == PgMoney(12345))); From 75b45c3323e0e3607e62aaf589583a1430c1e0ec Mon Sep 17 00:00:00 2001 From: firebladed <34522909+firebladed@users.noreply.github.com> Date: Fri, 12 Jun 2026 01:49:58 +0100 Subject: [PATCH 6/6] fix whitespace --- tests/postgres/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/postgres/types.rs b/tests/postgres/types.rs index 2a9576154f..b84f09836d 100644 --- a/tests/postgres/types.rs +++ b/tests/postgres/types.rs @@ -668,7 +668,7 @@ test_prepared_type!(interval( "INTERVAL 'infinity'" == PgInterval::INFINITY, "INTERVAL '-infinity'" - == PgInterval::NEG_INFINITY, + == PgInterval::NEG_INFINITY, )); test_prepared_type!(money(Postgres, "123.45::money" == PgMoney(12345)));