fixed postgresql groupby restrictions