Postgres Error Aggregate Function Calls Cannot Contain