pub fn jsonb_remove_0<J: JsonOrNullableJsonOrJsonbOrNullableJsonb + SingleValue, json>(
json: json,
) -> jsonb_remove_0<J, json>where
json: AsExpression<J>,
sqlite
only.Expand description
The jsonb_remove(X,P,...)
SQL function takes a single JSON value as its first argument followed by
zero or more path arguments. The jsonb_remove(X,P,...)
function returns a copy of the X parameter
with all the elements identified by path arguments removed. Paths that select elements not found in X
are silently ignored.
Removals occurs sequentially from left to right. Changes caused by prior removals can affect the path search for subsequent arguments.
If the jsonb_remove(X)
function is called with no path arguments, then it returns the input X
reformatted, with excess whitespace removed.
The jsonb_remove()
function throws an error if any of the path arguments is not a well-formed path.
This function returns value in a binary JSONB format.
This function requires at least SQLite 3.38 or newer
§Examples
let json = json!(['a', 'b', 'c', 'd']);
let result = diesel::select(jsonb_remove_0::<Jsonb, _>(json))
.get_result::<Option<serde_json::Value>>(connection)?;
assert_eq!(Some(json!(['a', 'b', 'c', 'd'])), result);
// Values are removed sequentially from left to right.
let json = json!(['a', 'b', 'c', 'd']);
let result = diesel::select(jsonb_remove_2::<Jsonb, _, _, _>(json, "$[0]", "$[2]"))
.get_result::<Option<serde_json::Value>>(connection)?;
assert_eq!(Some(json!(['b', 'c'])), result);
let json = json!({"a": 10, "b": 20});
let result = diesel::select(jsonb_remove_1::<Jsonb, _, _>(json, "$.a"))
.get_result::<Option<serde_json::Value>>(connection)?;
assert_eq!(Some(json!({"b": 20})), result);
// Paths that select not existing elements are silently ignored.
let json = json!({"a": 10, "b": 20});
let result = diesel::select(jsonb_remove_1::<Jsonb, _, _>(json, "$.c"))
.get_result::<Option<serde_json::Value>>(connection)?;
assert_eq!(Some(json!({"a": 10, "b": 20})), result);
let json = json!({"a": 10, "b": 20});
let result = diesel::select(jsonb_remove_1::<Jsonb, _, _>(json, "$"))
.get_result::<Option<serde_json::Value>>(connection)?;
assert_eq!(None, result);
§Variadic functions
This function is variadic in SQL, so there’s a family of functions on a diesel side:
jsonb_remove_0
, jsonb_remove_1
, … jsonb_remove_n
Here, the postfix number indicates repetitions of variadic arguments. To use this function, the appropriate version with the correct argument count must be selected.
§Controlling the generation of variadic function variants
By default, only variants with 0, 1, and 2 repetitions of variadic
arguments are generated. To generate more variants, set the
DIESEL_VARIADIC_FUNCTION_ARGS
environment variable to the desired
number of variants.
For a greater convenience this environment variable can also be set
in a .cargo/config.toml
file as described in the
cargo documentation.