diff --git a/sqlx-postgres/src/types/chrono/date.rs b/sqlx-postgres/src/types/chrono/date.rs index 475f41f4..5fc0a8f0 100644 --- a/sqlx-postgres/src/types/chrono/date.rs +++ b/sqlx-postgres/src/types/chrono/date.rs @@ -23,7 +23,11 @@ impl PgHasArrayType for NaiveDate { impl Encode<'_, Postgres> for NaiveDate { fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> Result { // DATE is encoded as the days since epoch - let days = (*self - postgres_epoch_date()).num_days() as i32; + let days: i32 = (*self - postgres_epoch_date()) + .num_days() + .try_into() + .map_err(|_| format!("value {self:?} would overflow binary encoding for Postgres DATE"))?; + Encode::::encode(days, buf) }