Revised patch, with one caveat: It contains copy/pasted code from variable.c intended to bridge the gap untilhttps://commitfest.postgresql.org/12/799/ (changing ParseVariableBool to detect invalid boolean-ish strings) is merged. We may want to pause full-review of this patch pending resolution of that one. I'm happy to continue with the stop-gap in place.
Changes made:
- \elseif is now \elif
- Invalid boolean values now return an error
- ON_ERROR_STOP is respected in all errors raided by \if, \elsif, \else, \endif commands.
- Documentation gives a more real-world example of usage.
- Documentation gives a more explicit list of valid boolean values
- Regression tests for out-of-place \endif, \else, and \endif
- Regression test for invalid boolean values - Removal of debug detritus.
Changes not(yet) made:
- No TAP test for errors respecting ON_ERROR_STOP - function comments in psqlscan.l follow the style found in other comments there, which goes counter to global style.
I would suggest to assume false on everything else, and/or maybe to ignore the whole if/endif section in such cases.
+1, it also halves the number of values we have to support later.
After giving it some thought, I revise a little bit my opinion:
I think that if the value is evaluated to TRUE or FALSE, then fine. If it is anything else, then an error is raised (error message shown), which should also stop the script on "ON_ERROR_STOP", and if not the script continues with assuming the value was FALSE.