Changed array_agg() to sum() per Andrew Gierth's suggestion so as not to depend on ordering