pub fn tsrange<lower, upper, bound>(
lower: lower,
upper: upper,
bound: bound,
) -> tsrange<lower, upper, bound>where
lower: AsExpression<Nullable<Timestamp>>,
upper: AsExpression<Nullable<Timestamp>>,
bound: AsExpression<RangeBoundEnum>,
Available on crate feature
postgres_backend
only.Expand description
Returns range of timestamps without timezone
ยงExample
use diesel::dsl::tsrange;
use diesel::pg::sql_types::RangeBound;
use time::{PrimitiveDateTime, macros::datetime};
diesel::insert_into(posts)
.values(&[
versions.eq(tsrange(Some(datetime!(2020-01-01 0:00)), Some(datetime!(2021-01-01 0:00)), RangeBound::LowerBoundInclusiveUpperBoundInclusive)),
versions.eq(tsrange(None, Some(datetime!(2020-01-01 0:00)), RangeBound::LowerBoundInclusiveUpperBoundExclusive)),
]).execute(conn)?;
let cool_posts = posts.select(versions)
.load::<(Bound<PrimitiveDateTime>, Bound<PrimitiveDateTime>)>(conn)?;
assert_eq!(vec![
(Bound::Included(datetime!(2020-01-01 0:00)), Bound::Included(datetime!(2021-01-01 0:00))),
(Bound::Unbounded, Bound::Excluded(datetime!(2020-01-01 0:00))),
], cool_posts);