pub fn json_get_idx<'a, E>(
expr: E,
index: i32,
) -> SQLExpr<'a, PostgresValue<'a>, <E::SQLType as JsonType>::Field, Null, E::Aggregate, E::Sources>Expand description
Gets an array element by zero-based index (->), keeping the JSON type.
Negative indexes count from the end. The operand must be json or jsonb
(JsonType). The result is NULL when the index is out of range.
ยงExamples
use drizzle_postgres::expr::json_get_idx;
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 first = json_get_idx(data, 0);
assert_eq!(first.to_sql().sql(), "data -> CAST ($1 AS INTEGER)");