From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Greg Stark <stark(at)mit(dot)edu>, Erik Rijkers <er(at)xs4all(dot)nl>, 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-03-12 17:45:37 |
Message-ID: | CAKFQuwYsV+hLf_hDXrudpLR0DjGrVhDCCSHJQUbUACXCvHbqkg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Sun, Mar 12, 2017 at 10:24 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> One point here is that we need to distinguish problems in the expression,
> which could arise from changing variable values, from some other types of
> mistakes like \elif with no preceding \if. When you see something like
> that you pretty much have to treat it as a no-op; but I don't think that's
> a problem for scripting usage.
>
One of my discarded write-ups from last night made a point that we don't
really distinguish between run-time and compile-time errors - possibly
because we haven't had to until now.
If we detect what would be considered a compile-time error (\elif after
\else for instance) we could treat anything that isn't a conditional
meta-command as a no-op with a warning (and exit in stop-script mode).
There are only four commands and a finite number of usage permutations.
Enumerating and figuring out the proper behavior for each should be done.
Thus - If the expressions are bad they are considered false but the block
is created
If the flow-control command is bad the system will tell the user why and
how to get back to a valid state - the entire machine state goes INVALID
until a corrective command is encountered.
For instance:
\if
\else
\elif
warning: elif block cannot occur directly within an \else block. either
start a new \if, \endif the current scope, or type \else to continue
entering commands into the existing else block. no expression evaluation
has occurred.
\echo 'c'
warning: command ignored in broken \if block scope - see prior correction
options
Yes, that's wordy, but if that was shown the user would be able to
recognize their situation and be able to get back to their desired state.
Figuring out what the valid correction commands are for each invalid state,
and where the user is left, is tedious but mechanical.
So we'd need an INVALID state as well as the existing IGNORE state.
\endif would always work - but take you up one nesting level
The user shouldn't need to memorize the invalid state rules. While we
could document them and point the reader there having them inline seems
preferable.
>
> We could imagine resolving this tension by treating failed \if expressions
> differently in interactive and noninteractive cases. But I fear that cure
> would be worse than the disease.
>
I don't think this becomes necessary - we should distinguish the error
types the same in both modes.
From | Date | Subject | |
---|---|---|---|
Next Message | Jan Michálek | 2017-03-12 18:21:18 | Re: Other formats in pset like markdown, rst, mediawiki |
Previous Message | Corey Huinker | 2017-03-12 17:40:15 | Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless) |