Skip to main content

in_array

Function in_array 

Source
pub fn in_array<'a, V, E, I, R>(
    expr: E,
    values: I,
) -> SQLExpr<'a, V, <V::DialectMarker as DialectTypes>::Bool, NonNull, E::Aggregate, (Arg<<E as Expr<'a, V>>::Nullable, <E as ExprSources>::Sources>, Arg<<R as ComparisonOperand<'a, V, E>>::Nullable, <R as ComparisonOperand<'a, V, E>>::Sources>)>
where V: SQLParam + 'a, E: Expr<'a, V>, I: IntoIterator<Item = R>, R: ComparisonOperand<'a, V, E>, E::SQLType: Compatible<<R as ComparisonOperand<'a, V, E>>::SQLType>,
Expand description

Membership in a list of values (expr IN (v1, v2, ...)).

values is any iterator, such as an array or Vec; each value must have a SQL type compatible with expr. An empty list renders FALSE, since nothing is in an empty list. The result is the dialect’s boolean, NULL when expr or a value is.

§Examples

let cond = in_array(users.name, ["alice", "bob"]);
assert_eq!(cond.sql(), r#""users"."name" IN (?, ?)"#);

let none = in_array(users.name, Vec::<&str>::new());
assert_eq!(none.sql(), "FALSE");

§Type safety

Values of an incompatible type do not compile:

ⓘ
let wrong = in_array(users.id, ["a", "b"]);