Function jsonb_group_array

Source
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.

§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

  • [json_group_array] will return data in JSON format instead of JSONB.
  • [jsonb_group_object] will return JSONB object instead of array.