pub fn json_extract_path_text_1<J: JsonOrNullableJson + SingleValue, T1: SingleValue + TextOrNullableText, json, text_1>(
json: json,
text_1: text_1,
) -> json_extract_path_text_1<J, T1, json, text_1>where
json: AsExpression<J>,
text_1: AsExpression<T1>,postgres_backend only.Expand description
Extracts JSON sub-object at the specified path as text. (This is functionally equivalent to the #>> operator.)
§Example
let expected = Some(String::from("{\"f5\":99,\"f6\":\"foo\"}"));
let result = diesel::select(json_extract_path_text_1::<Json, Text, _, _>(
json!({"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}),
"f4",
))
.get_result::<Option<String>>(connection)?;
assert_eq!(expected, result);
let expected = Some(String::from("foo"));
let result = diesel::select(json_extract_path_text_2::<Json, Text, Text, _, _, _>(
json!({"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}),
"f4",
"f6"
))
.get_result::<Option<String>>(connection)?;
assert_eq!(expected, result);
let result = diesel::select(json_extract_path_text_1::<Nullable<Json>, Text, _, _>(None::<serde_json::Value>, "f4"))
.get_result::<Option<String>>(connection)?;
assert_eq!(None::<String>, result);
let result = diesel::select(json_extract_path_text_2::<Json, Nullable<Text>, Text, _, _, _>(json!({"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}), None::<String>, "f6"))
.get_result::<Option<String>>(connection)?;
assert_eq!(None::<String>, result);
§Variadic functions
This function is variadic in SQL, so there’s a family of functions on a diesel side:
json_extract_path_text_0, json_extract_path_text_1, … json_extract_path_text_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.