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/3] 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/3] 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/3] 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