fixed  PostgreSQL error with group by query in the template page