pub fn jsonb_group_array<E: SqlType + SingleValue, elements>(
elements: elements,
) -> jsonb_group_array<E, elements>where
elements: AsExpression<E>,
Available on crate feature
sqlite
only.Expand description
The jsonb_group_array(X)
function is an aggregate SQL function that returns a JSONB array comprised of
all X values in the aggregation.
§Aggregate Function Expression
This function can be used as aggregate expression. See AggregateExpressionMethods
for details.
§Examples
§Normal function usage
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]));
§Aggregate function expression
let result = animals
.select(json_group_array(species).aggregate_filter(legs.lt(8)))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(result, json!(["dog"]));
§See also
json_group_array
will return data in JSON format instead of JSONB.jsonb_group_object
will return JSONB object instead of array.