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

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Greg Stark <stark(at)mit(dot)edu>
Cc: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, Erik Rijkers <er(at)xs4all(dot)nl>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Daniel Verite <daniel(at)manitou-mail(dot)org>, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, 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-12 08:07:03
Message-ID: alpine.DEB.2.20.1702120823010.26448@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hello Greg,

>> So you'd just want to know nesting depth, with no indicator of true/false?
>
> Even that's more than bash does, for example: [...]

Indeed, there is nothing in "bash" prompt about nesting control
structures. However other shells have such indications: "zsh" has "%_",
"tcsh" has "%R". In tcsh for example, there is mention of the structure
type but none of nesting depth nor truth:

> if ( 0 ) then
if? ...

> I'm a bit confused how the true/false is actually valuable.

The point is just to tell the user that the next command (1) is under an
if control structure and (2) whether it is going to be executed or
ignored. That is not too bad in 2 characters.

> It doesn't tell you how the expression actually evaluated,

I do not get your point... t tells that it was true, f that it was false?

> just where you are in the code you're typing in which you can tell
> equally well by looking at what code you're typing in.

SELECT ... AS condition \gset
\if :condition ...

The value of the condition is not obvious from the code, it depends on the
database state.

> The reason nesting level is handy is just to remind you in case you
> forget.

Sure, that can be useful too.

> For debugging scripts it would be handy to have some way to tell
> whether the \if expression actually evaluated to true or false but
> that wouldn't be in the prompt I don't think.

Are you suggest to add another command to display the current stack state,
eg "\ifstate" or whatever?

"\if" is really about scripting, so the idea was to have something quite
light for interactive debugging, especially to help the user not to be
stuck into a false branch, hence the prompt information with t/f/z.

What should be in the prompt is indeed debatable: existence, nesting
depth, current truth value, part of the stack... I think that something,
whatever it is, is necessary.

Maybe this can be a discussed in a follow-up patch and Corey should
proceed to finalize the if patch?

--
Fabien

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Rasheed 2017-02-12 10:35:04 Re: multivariate statistics (v19)
Previous Message Amit Kapila 2017-02-12 02:49:42 Re: amcheck (B-Tree integrity checking tool)