diesel::pg::expression::dsl

Function tstzrange

source
pub fn tstzrange<lower, upper, bound>(
    lower: lower,
    upper: upper,
    bound: bound,
) -> tstzrange<lower, upper, bound>
Available on crate feature postgres_backend only.
Expand description

Returns range of timestamps with timezone

ยงExample

use diesel::dsl::tstzrange;
use diesel::pg::sql_types::RangeBound;
use time::{OffsetDateTime, macros::datetime};

diesel::insert_into(posts)
    .values(&[
       versions.eq(tstzrange(Some(datetime!(2020-01-01 0:00 UTC)), Some(datetime!(2021-01-01 0:00 -3)), RangeBound::LowerBoundInclusiveUpperBoundInclusive)),
       versions.eq(tstzrange(None, Some(datetime!(2020-01-01 0:00 +2)), RangeBound::LowerBoundInclusiveUpperBoundExclusive)),
    ]).execute(conn)?;

let cool_posts = posts.select(versions)
    .load::<(Bound<OffsetDateTime>, Bound<OffsetDateTime>)>(conn)?;
assert_eq!(vec![
         (Bound::Included(datetime!(2020-01-01 0:00 UTC)), Bound::Included(datetime!(2021-01-01 0:00 -3))),
         (Bound::Unbounded, Bound::Excluded(datetime!(2020-01-01 0:00 +2))),
     ], cool_posts);