Skip to main content

jsonb_contained

Function jsonb_contained 

Source
pub fn jsonb_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>>, L::SQLType: JsonbType, R: Expr<'a, PostgresValue<'a>>, R::SQLType: JsonbOperand,
Expand description

Tests whether the left jsonb value is contained in the right one (<@).

The left operand must be jsonb (JsonbType). The right operand may be json, jsonb, or JSON text (JsonbOperand); it is cast to jsonb. The result is NULL when either operand is NULL.

ยงExamples

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

let data = raw_non_null::<PostgresValue, Jsonb>("data");
let cond = jsonb_contained(data, r#"{"role": "admin", "active": true}"#);
assert_eq!(cond.to_sql().sql(), "data <@ CAST ($1 AS JSONB)");