fix issue with group by caused by PostgreSQL