Postgresql Boolean Functions Python Code