Skip to main content

jsonb_contains

Function jsonb_contains 

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

Tests whether the left jsonb value contains 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_contains;
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_contains(data, r#"{"role": "admin"}"#);
assert_eq!(cond.to_sql().sql(), "data @> CAST ($1 AS JSONB)");