Make psql reject attempts to set special variables to invalid values.
Tom Lane <tgl@sss.pgh.pa.us>
Make psql reject attempts to set special variables to invalid values. Previously, if the user set a special variable such as ECHO to an unrecognized value, psql would bleat but store the new value anyway, and then fall back to a default setting for the behavior controlled by the variable. This was agreed to be a not particularly good idea. With this patch, invalid values result in an error message and no change in state. (But this applies only to variables that affect psql's behavior; purely informational variables such as ENCODING can still be set to random values.) To do this, modify the API for psql's assign-hook functions so that they can return an OK/not OK result, and give them the responsibility for printing error messages when they reject a value. Adjust the APIs for ParseVariableBool and ParseVariableNum to support the new behavior conveniently. In passing, document the variable VERSION, which had somehow escaped that. And improve the quite-inadequate commenting in psql/variables.c. Daniel Vérité, reviewed by Rahila Syed, some further tweaking by me Discussion: https://postgr.es/m/7356e741-fa59-4146-a8eb-cf95fd6b21fb@mm
Files
| Path | Change | +/− |
|---|---|---|
| doc/src/sgml/ref/psql-ref.sgml | modified | +21 −12 |
| src/bin/psql/command.c | modified | +46 −36 |
| src/bin/psql/common.c | modified | +0 −1 |
| src/bin/psql/input.c | modified | +1 −1 |
| src/bin/psql/mainloop.c | modified | +1 −1 |
| src/bin/psql/startup.c | modified | +72 −49 |
| src/bin/psql/variables.c | modified | +163 −65 |
| src/bin/psql/variables.h | modified | +34 −16 |
| src/test/regress/expected/psql.out | modified | +10 −1 |
| src/test/regress/sql/psql.sql | modified | +8 −0 |
Documentation touched
Discussion
- Improvements in psql hooks for variables 54 messages · 2016-09-16 → 2017-02-02