Corey Huinker wrote:
> > \if ERROR
> > \echo X
> > \else
> > \echo Y
> > \endif
> >
> > having both X & Y printed and error reported on else and endif. I think
> > that an expression error should just put the stuff in ignore state.
> >
>
> Not just false, but ignore the whole if-endif? interesting. I hadn't
> thought of that. Can do.
If we use the Unix shell as a model, in POSIX "test" and "if"
are such that an evaluation error (exit status>1) leads to the same
flow than when evaluating to false (exit status=1).
References I can find:
test:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
if:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_04_07
BTW, in "set -e" mode, it also says that a failure to evaluate an "if"expression does not lead to the script stopping:
<quote> The -e setting shall be ignored when executing the compound list following the while, until, if, or elif
reservedword, a pipeline beginning with the ! reserved word, or any command of an AND-OR list other than the last
</quote>
So psql is not following that model with ON_ERROR_STOP if it exits
with an error when unable to evaluate an "if" expression.
I'm not implying that we should necessarily adopt the shell behavior,
but as these choices have certainly been made in POSIX for good
reasons, we should make sure to think twice about why they don't
apply to psql.
Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite