Skip to content

Commit

Permalink
Fix bug with converting a pg_sys::Datum into a pgrx::Date (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
eeeebbbbrrrr committed Jun 20, 2023
1 parent ecbf925 commit f806a69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pgrx-tests/src/tests/datetime_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,4 +573,12 @@ mod tests {
assert_eq!(result, Interval::new(6, 15, 42)?);
Ok(())
}

#[pg_test]
fn test_old_date() -> Result<(), Box<dyn std::error::Error>> {
let array = Spi::get_one::<Array<Date>>("SELECT ARRAY['1977-07-04']::date[]")?.unwrap();
let first = array.into_iter().next();
assert_eq!(first, Some(Some(Date::from_str("1977-07-04")?)));
Ok(())
}
}
2 changes: 1 addition & 1 deletion pgrx/src/datum/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl TryFrom<pg_sys::Datum> for Date {

#[inline]
fn try_from(datum: pg_sys::Datum) -> Result<Self, Self::Error> {
pg_sys::DateADT::try_from(datum.value() as isize).map(|d| Date(d))
Ok(Date(datum.value() as pg_sys::DateADT))
}
}

Expand Down

0 comments on commit f806a69

Please sign in to comment.