diesel::pg::expression::dsl

Function array_length

source
pub fn array_length<Arr: ArrayOrNullableArray + SingleValue, array, dimension>(
    array: array,
    dimension: dimension,
) -> array_length<Arr, array, dimension>
where array: AsExpression<Arr>, dimension: AsExpression<Integer>,
Available on crate feature postgres_backend only.
Expand description

Returns the length of the requested array

ยงExample

let result = diesel::select(array_length::<Array<Integer>, _, _>(vec![1, 2, 3], 1))
    .get_result::<Option<i32>>(connection)?;
assert_eq!(Some(3), result);

let result = diesel::select(array_length::<Array<Integer>, _, _>(vec![1, 2, 3], 2))
    .get_result::<Option<i32>>(connection)?;
assert_eq!(None, result);

let result = diesel::select(array_length::<Nullable<Array<Integer>>, _, _>(None::<Vec<i32>>, 1))
    .get_result::<Option<i32>>(connection)?;
assert_eq!(None, result);