diesel::pg::expression::dsl

Function array_append

source
pub fn array_append<Arr: ArrayOrNullableArray<Inner = T> + SingleValue, T: SingleValue, a, e>(
    a: a,
    e: e,
) -> array_append<Arr, T, a, e>
where a: AsExpression<Arr>, e: AsExpression<T>,
Available on crate feature postgres_backend only.
Expand description

Append an element to the end of an array

ยงExample

let ints = diesel::select(array_append::<Array<_>, Integer, _, _>(vec![1, 2], 3))
    .get_result::<Vec<i32>>(connection)?;
assert_eq!(vec![1, 2, 3], ints);

let ints = diesel::select(array_append::<Array<_>, Nullable<Integer>, _, _>(vec![Some(1), Some(2)], None::<i32>))
    .get_result::<Vec<Option<i32>>>(connection)?;
assert_eq!(vec![Some(1), Some(2), None], ints);

let ints = diesel::select(array_append::<Nullable<Array<_>>, Integer, _, _>(None::<Vec<i32>>, 3))
    .get_result::<Vec<i32>>(connection)?;
assert_eq!(vec![3], ints);

let ints = diesel::select(array_append::<Nullable<Array<_>>, Nullable<Integer>, _, _>(None::<Vec<i32>>, None::<i32>))
    .get_result::<Vec<Option<i32>>>(connection)?;
assert_eq!(vec![None], ints);