Skip to main content

json_get_path

Function json_get_path 

Source
pub fn json_get_path<'a, E>(
    expr: E,
    path: &'a str,
) -> SQLExpr<'a, PostgresValue<'a>, <E::SQLType as JsonType>::Field, Null, E::Aggregate, E::Sources>
where E: Expr<'a, PostgresValue<'a>>, E::SQLType: JsonType,
Expand description

Gets the value at a path (#>), keeping the JSON type.

path is a PostgreSQL text-array literal such as "{address,city}"; array indexes go in the path as numbers ("{tags,0}"). The operand must be json or jsonb (JsonType). The result is NULL when the path does not exist.

ยงExamples

use drizzle_postgres::expr::json_get_path;
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 city = json_get_path(data, "{address,city}");
assert_eq!(city.to_sql().sql(), "data #> CAST ($1 AS TEXT[])");