Postgresql Max Integer Value In Python Iteration