pub fn array_prepend<T: SingleValue, Arr: ArrayOrNullableArray<Inner = T> + SingleValue, e, a>(
e: e,
a: a,
) -> array_prepend<T, Arr, e, a>where
e: AsExpression<T>,
a: AsExpression<Arr>,
Available on crate feature
postgres_backend
only.Expand description
Prepends an element to the beginning of an array
ยงExample
let ints = diesel::select(array_prepend::<Integer, Array<_>, _, _>(3, vec![1, 2]))
.get_result::<Vec<i32>>(connection)?;
assert_eq!(vec![3, 1, 2], ints);
let ints = diesel::select(array_prepend::<Nullable<Integer>, Array<_>, _, _>(None::<i32>, vec![Some(1), Some(2)]))
.get_result::<Vec<Option<i32>>>(connection)?;
assert_eq!(vec![None, Some(1), Some(2)], ints);
let ints = diesel::select(array_prepend::<Integer, Nullable<Array<_>>, _, _>(3, None::<Vec<i32>>))
.get_result::<Vec<i32>>(connection)?;
assert_eq!(vec![3], ints);
let ints = diesel::select(array_prepend::<Nullable<Integer>, Nullable<Array<_>>, _, _>(None::<i32>, None::<Vec<i32>>))
.get_result::<Vec<Option<i32>>>(connection)?;
assert_eq!(vec![None], ints);