Skip to main content

like

Function like 

Source
pub fn like<'a, V, L, R>(
    left: L,
    pattern: R,
) -> SQLExpr<'a, V, <V::DialectMarker as DialectTypes>::Bool, NonNull, <L::Aggregate as AggregateKind>::Or<<R as ComparisonOperand<'a, V, L>>::Aggregate>, (Arg<<L as Expr<'a, V>>::Nullable, <L as ExprSources>::Sources>, Arg<<R as ComparisonOperand<'a, V, L>>::Nullable, <R as ComparisonOperand<'a, V, L>>::Sources>)>
where V: SQLParam + 'a, L: Expr<'a, V>, R: ComparisonOperand<'a, V, L>, L::SQLType: Compatible<<R as ComparisonOperand<'a, V, L>>::SQLType> + Textual, <R as ComparisonOperand<'a, V, L>>::SQLType: Textual,
Expand description

Pattern match (LIKE).

Renders left LIKE pattern. Both sides must be text. In the pattern, % matches any run of characters and _ matches one character. The result is the dialect’s boolean, NULL when either side is. Case sensitivity follows the database: SQLite and MySQL (with its default collations) ignore case, PostgreSQL does not.

§Examples

let starts_with_a = like(users.name, "A%");
assert_eq!(starts_with_a.sql(), r#""users"."name" LIKE ?"#);

§Type safety

LIKE on an integer column does not compile:

ⓘ
let wrong = like(users.id, "1%");