Fix group query for pg