fix for postgres group by