Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Daniel Verite <daniel(at)manitou-mail(dot)org>
Cc: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, PostgreSQL <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
Date: 2017-01-30 17:35:37
Message-ID: alpine.DEB.2.20.1701301816290.30145@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hello Daniel,

> [...] 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.

Interesting point.

The shell is about processes, and if relies on the status code returned,
with 0 meaning true, and anything else, which is somehow a process error,
meaning false. So there is no way to distinguish false from process error
in this system, because the status is just one integer.

However, a syntax error, for instance with a shell internal test, leads to
nothing being executed:

bash> if [[ bad syntax ]] ; then echo then ; else echo else ; fi
-bash: conditional binary operator expected
-bash: syntax error near `syntax'
# nothing is echoed

Another example with python in interactive mode:

python> if 1+: print 1; else print 0
SyntaxError: invalid syntax
# nothing is printed

So rejecting execution altogether on syntax errors is somehow a common
practice.

--
Fabien.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2017-01-30 17:45:23 Re: Subtle bug in "Simplify tape block format" commit
Previous Message Peter Eisentraut 2017-01-30 17:34:41 Re: sequence data type