Skip to main content

array_overlaps

Function array_overlaps 

Source
pub fn array_overlaps<'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 two arrays share at least one element (&&).

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_overlaps, PgArray};
use drizzle_postgres::values::PostgresValue;
use drizzle_types::{Array, postgres::types::Int4};

let team_ids = raw_non_null::<PostgresValue, Array<Int4>>("team_ids");
// Rows in team 1 or team 2.
let condition = array_overlaps(team_ids, PgArray(vec![1_i32, 2]));
assert_eq!(condition.to_sql().sql(), "team_ids && $1");