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-shared 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.
This function requires at least SQLite 3.45 or newer
§Aggregate Function Expression
This function can be used as aggregate expression. See AggregateExpressionMethods for details.
§Examples
§Normal function usage
let result = animals
.select(jsonb_group_array(species))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(result, json!(["dog", "spider"]));
let result = animals
.select(jsonb_group_array(legs))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(result, json!([4, 8]));
let result = animals
.select(jsonb_group_array(name))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(result, json!(["Jack", null]));
§Aggregate function expression
let result = animals
.select(jsonb_group_array(species).aggregate_filter(legs.lt(8)))
.get_result::<serde_json::Value>(connection)?;
assert_eq!(result, json!(["dog"]));
§See also
json_group_arraywill return data in JSON format instead of JSONB.jsonb_group_objectwill return JSONB object instead of array.