diesel::prelude

Trait PgBinaryExpressionMethods

Source
pub trait PgBinaryExpressionMethods: Expression + Sized {
    // Provided methods
    fn concat<T>(self, other: T) -> Concat<Self, T>
       where Self::SqlType: SqlType,
             T: AsExpression<Self::SqlType> { ... }
    fn like<T>(self, other: T) -> Like<Self, T>
       where Self::SqlType: SqlType,
             T: AsExpression<Self::SqlType> { ... }
    fn not_like<T>(self, other: T) -> NotLike<Self, T>
       where Self::SqlType: SqlType,
             T: AsExpression<Self::SqlType> { ... }
}
Available on crate feature postgres_backend only.
Expand description

PostgreSQL specific methods present on Binary expressions.

Provided Methods§

Source

fn concat<T>(self, other: T) -> Concat<Self, T>
where Self::SqlType: SqlType, T: AsExpression<Self::SqlType>,

Concatenates two PostgreSQL byte arrays using the || operator.

§Example
let names = users.select(name.concat(" the Greatest".as_bytes())).load(connection);
let expected_names = vec![
    b"Sean the Greatest".to_vec(),
    b"Tess the Greatest".to_vec()
];
assert_eq!(Ok(expected_names), names);

// If the value is nullable, the output will be nullable
let names = users.select(hair_color.concat("ish".as_bytes())).load(connection);
let expected_names = vec![
    Some(b"Greenish".to_vec()),
    None,
];
assert_eq!(Ok(expected_names), names);
Source

fn like<T>(self, other: T) -> Like<Self, T>
where Self::SqlType: SqlType, T: AsExpression<Self::SqlType>,

Creates a PostgreSQL binary LIKE expression.

This method is case sensitive. There is no case-insensitive equivalent as of PostgreSQL 14.

§Examples
let starts_with_s = users
    .select(name)
    .filter(name.like(b"S%".to_vec()))
    .load(connection);
assert_eq!(Ok(vec![b"Sean".to_vec()]), starts_with_s);
Source

fn not_like<T>(self, other: T) -> NotLike<Self, T>
where Self::SqlType: SqlType, T: AsExpression<Self::SqlType>,

Creates a PostgreSQL binary LIKE expression.

This method is case sensitive. There is no case-insensitive equivalent as of PostgreSQL 14.

§Examples
let starts_with_s = users
    .select(name)
    .filter(name.not_like(b"S%".to_vec()))
    .load(connection);
assert_eq!(Ok(vec![b"Tess".to_vec()]), starts_with_s);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§