Skip to main content

array_contained

Function array_contained 

Source
pub fn array_contained<'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 every element of the left array is in 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_contained, PgArray};
use drizzle_postgres::values::PostgresValue;
use drizzle_types::{Array, postgres::types::Text};

let tags = raw_non_null::<PostgresValue, Array<Text>>("tags");
// Rows whose tags all come from the allowed list.
let condition = array_contained(tags, PgArray(vec!["rust", "sql", "web"]));
assert_eq!(condition.to_sql().sql(), "tags <@ $1");