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

From: Erik Rijkers <er(at)xs4all(dot)nl>
To: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, Daniel Verite <daniel(at)manitou-mail(dot)org>, PostgreSQL <pgsql-hackers(at)postgresql(dot)org>, pgsql-hackers-owner(at)postgresql(dot)org
Subject: Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
Date: 2017-02-03 11:00:49
Message-ID: 1927c741db54ebc5a93374df337591e1@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2017-02-03 08:16, Corey Huinker wrote:

> 0001.if_endif.v5.diff

1. Well, with this amount of interactive output it is impossible to get
stuck without knowing :)
This is good. Still, it would be an improvement to be able to break out
of an inactive \if-branch
with Ctrl-C. (I noticed that inside an active branch it is already
possible )
'\endif' is too long to type, /and/ you have to know it.

2. Inside an \if block \q should be given precedence and cause a direct
exit of psql (or at the
very least exit the if block(s)), as in regular SQL statements
(compare: 'select * from t \q' which will immediately exit psql --
this is good. )

3. I think the 'barking' is OK because interactive use is certainly not
the first use-case.
But nonetheless it could be made a bit more terse without losing its
function.
The interactive behavior is now:
# \if 1
entered if: active, executing commands
# \elif 0
entered elif: inactive, ignoring commands
# \else
entered else: inactive, ignoring commands
# \endif
exited if: active, executing commands

It really is a bit too wordy, IMHO; I would say, drop all 'entered',
'active', and 'inactive' words.
That leaves it plenty clear what's going on.
That would make those lines:
if: executing commands
elif: ignoring commands
else: ignoring commands
exited if
(or alternatively, just mention 'if: active' or 'elif: inactive',
etc., which has the advantage of being shorter)

5. A real bug, I think:
#\if asdasd
unrecognized value "asdasd" for "\if <expr>": boolean expected
# \q;
inside inactive branch, command ignored.
#

That 'unrecognized value' message is fair enough but it is
counterintuitive that after an erroneous opening \if-expression, the
if-modus should be entered into. ( and now I have to type \endif
again... )

6. About the help screen:
There should be an empty line above 'Conditionals' to visually divide it
from other help items.

The indenting of the new block is incorrect: the lines that start with
fprintf(output, _(" \\
are indented to the correct level; the other lines are indented 1 place
too much.

The help text has a few typos (some multiple times):
queires -> queries
exectue -> execute
subsequennt -> subsequent

Thanks,

Erik Rijkers

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2017-02-03 11:06:04 Re: pgsql: pageinspect: Try to fix some bugs in previous commit.
Previous Message Pavel Stehule 2017-02-03 10:52:07 Re: Harmonization of json functions (SQLITE)