Use bash and the postgres built-in array_agg