group by fix for postgres