pub fn array_position_with_subscript<Arr: ArrayOrNullableArray<Inner = E> + SingleValue, E: SingleValue, a, elem, subscript>(
    a: a,
    elem: elem,
    subscript: subscript,
) -> array_position_with_subscript<Arr, E, a, elem, subscript>
where a: AsExpression<Arr>, elem: AsExpression<E>, subscript: AsExpression<Integer>,
Available on crate feature postgres_backend only.
Expand description

Returns the subscript of the first occurrence of the second argument in the array, or NULL if it’s not present, beginning at the subscript given as the third argument.

The array must be one-dimensional. Comparisons are done using IS NOT DISTINCT FROM semantics, so it is possible to search for NULL.

§Example


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

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

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

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