diesel::pg::expression::dsl

Function range_merge

source
pub fn range_merge<R1: RangeOrNullableRange + SingleValue, R2: RangeOrNullableRange<Inner = R1::Inner> + SingleValue + CombinedNullableValue<R1, Range<R1::Inner>>, lhs, rhs>(
    lhs: lhs,
    rhs: rhs,
) -> range_merge<R1, R2, lhs, rhs>
where lhs: AsExpression<R1>, rhs: AsExpression<R2>,
Available on crate feature postgres_backend only.
Expand description

Returns the smallest range which includes both of the given ranges

ยงExample

let int = diesel::select(range_merge::<Range<Integer>, Range<_>,  _, _>(5..11, 10..)).get_result::<(Bound<i32>, Bound<i32>)>(connection)?;
assert_eq!((Bound::Included(5), Bound::Unbounded), int);

let int = diesel::select(range_merge::<Range<Integer>, Range<_>,  _, _>(1..3, 7..10)).get_result::<(Bound<i32>, Bound<i32>)>(connection)?;
assert_eq!((Bound::Included(1), Bound::Excluded(10)), int);

let int = diesel::select(range_merge::<Nullable<Range<Integer>>, Nullable<Range<_>>,  _, _>(None::<std::ops::Range<i32>>, 7..10)).get_result::<Option<(Bound<i32>, Bound<i32>)>>(connection)?;
assert_eq!(None, int);

let int = diesel::select(range_merge::<Nullable<Range<Integer>>, Nullable<Range<_>>,  _, _>(1..3, None::<std::ops::Range<i32>>)).get_result::<Option<(Bound<i32>, Bound<i32>)>>(connection)?;
assert_eq!(None, int);