get GROUP BY clauses to work with Postgres