Postgres For Loop Continue And Break In Python While Loop