[HACKERS] Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if,\quit_unless) - Mailing list pgsql-hackers

From Fabien COELHO
Subject [HACKERS] Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if,\quit_unless)
Date
Msg-id alpine.DEB.2.20.1702120823010.26448@lancre
Whole thread Raw
In response to Re: [HACKERS] \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)  (Greg Stark <stark@mit.edu>)
Responses Re: [HACKERS] \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
List 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



pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: [HACKERS] amcheck (B-Tree integrity checking tool)
Next
From: Dean Rasheed
Date:
Subject: Re: [HACKERS] multivariate statistics (v19)