0
votes

Using the latest r2d2_postgres crate, I need to read intervals from Postgres 13. When I send the following query:

SELECT '1 year 2 month 3 week 4 day 5 hour 6 minute 7.123456789 second'::interval

These bytes are returned in a vector:

[0, 0, 0, 4, 70, 196, 16, 1, 0, 0, 0, 25, 0, 0, 0, 14]

How to parse these?

I know of the pg_interval crate, but the from_sql method seems to take a string slice instead of a u8 vector.

1

1 Answers

0
votes

An example taken from the same crate:

impl<'a> FromSql<'a> for Interval {
    fn from_sql(_: &Type, mut raw: &'a [u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
        let microseconds = raw.get_i64();
        let days = raw.get_i32();
        let months = raw.get_i32();
        ...