pub fn json_group_array<E: SqlType + SingleValue, elements>(
elements: elements,
) -> json_group_array<E, elements>where
elements: AsExpression<E>,
Available on crate feature
sqlite
only.Expand description
The json_group_array(X)
function is an aggregate SQL function that returns a JSON array comprised of
all X values in the aggregation.
§Examples
let result = animals.select(json_group_array(species)).get_result::<serde_json::Value>(connection)?;
assert_eq!(result, json!(["dog", "spider"]));
let result = animals.select(json_group_array(legs)).get_result::<serde_json::Value>(connection)?;
assert_eq!(result, json!([4, 8]));
let result = animals.select(json_group_array(name)).get_result::<serde_json::Value>(connection)?;
assert_eq!(result, json!(["Jack", null]));
§See also
- [
jsonb_group_array
] will return data in JSONB format instead of JSON. - [
json_group_object
] will return JSON object instead of array.