Skip to main content

array_contains

Function array_contains 

Source
pub fn array_contains<'a, L, R>(
    left: L,
    right: R,
) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, <L::Aggregate as AggregateKind>::Or<R::Aggregate>, (Arg<L::Nullable, L::Sources>, Arg<R::Nullable, R::Sources>)>
where L: Expr<'a, PostgresValue<'a>>, R: Expr<'a, PostgresValue<'a>>, L::SQLType: ArrayOperand<R::SQLType>,
Expand description

Tests whether the left array contains every element of the right array (@>).

Both operands must be arrays with compatible element types; see ArrayOperand. The result is boolean, and NULL when either operand is NULL.

ยงExamples

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

let tags = raw_non_null::<PostgresValue, Array<Text>>("tags");
// Rows tagged with both "rust" and "sql" (and possibly more).
let condition = array_contains(tags, PgArray(vec!["rust", "sql"]));
assert_eq!(condition.to_sql().sql(), "tags @> $1");