fix postgresql group by