select m, array_agg(p) as ps from ... where u = N group by m;