As far as the original problem goes, I wonder whether what you really want isn't a \quit command that lets you specify psql's exit code.
Actually, I'm seeing this as basically an assertion capability and maybe should be named as such\assert_is\assert_isnot
pgsql-hackers by date:
Соглашаюсь с условиями обработки персональных данных