Postgresql While Loop Exit Python Environment Compiler