Skip to main content

ilike

Function ilike 

Source
pub fn ilike<'a, E, P>(
    expr: E,
    pattern: P,
) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, <<E as Expr<'a, PostgresValue<'a>>>::Aggregate as AggregateKind>::Or<<P as ComparisonOperand<'a, PostgresValue<'a>, E>>::Aggregate>, (Arg<<E as Expr<'a, PostgresValue<'a>>>::Nullable, <E as ExprSources>::Sources>, Arg<<P as ComparisonOperand<'a, PostgresValue<'a>, E>>::Nullable, <P as ComparisonOperand<'a, PostgresValue<'a>, E>>::Sources>)>
Expand description

Matches a text expression against a LIKE pattern, ignoring case (ILIKE).

In the pattern, % matches any run of characters and _ matches one character. The result is a boolean condition for WHERE, HAVING or a join, and is NULL when either operand is NULL.

§Examples

use drizzle_core::{ToSQL, expr::raw_non_null};
use drizzle_postgres::expr::ilike;
use drizzle_postgres::values::PostgresValue;
use drizzle_types::postgres::types::Text;

// Stands in for a `name text NOT NULL` column.
let name = raw_non_null::<PostgresValue, Text>("name");
let cond = ilike(name, "%john%"); // matches "John", "JOHNNY", ...
assert_eq!(cond.to_sql().sql(), "name ILIKE $1");

§Type safety

Both sides must be text.

ⓘ
use drizzle_core::expr::raw_non_null;
use drizzle_postgres::expr::ilike;
use drizzle_postgres::values::PostgresValue;
use drizzle_types::postgres::types::Int4;

let age = raw_non_null::<PostgresValue, Int4>("age");
let _ = ilike(age, "%1%"); // `int4` is not textual