fix for postgres group by take 2