Postgresql While Loop Exit In Python The