From 511ae628f31b4e791cd5c7836e46cb84dcf145fd Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 30 Jan 2017 16:37:15 -0500 Subject: Make psql reject attempts to set special variables to invalid values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- doc/src/sgml/ref/psql-ref.sgml | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 640fe12bbf6..4e51e90906c 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -3078,10 +3078,8 @@ bar by psql. They represent certain option settings that can be changed at run time by altering the value of the variable, or in some cases represent changeable state of - psql. Although - you can use these variables for other purposes, this is not - recommended, as the program behavior might grow really strange - really quickly. By convention, all specially treated variables' names + psql. + By convention, all specially treated variables' names consist of all upper-case ASCII letters (and possibly digits and underscores). To ensure maximum compatibility in the future, avoid using such variable names for your own purposes. A list of all specially @@ -3170,12 +3168,11 @@ bar start-up, use the switch . If set to queries, psql prints each query to standard output - as it is sent to the server. The switch for this is + as it is sent to the server. The switch to select this behavior is . If set to errors, then only failed queries are displayed on standard error output. The switch - for this is . If unset, or if set to - none (or any other value than those above) then - no queries are displayed. + for this behavior is . If unset, or if set to + none, then no queries are displayed. @@ -3201,6 +3198,9 @@ bar The current client character set encoding. + This is set every time you connect to a database (including + program start-up), and when you change the encoding + with \encoding, but it can be unset. @@ -3241,9 +3241,8 @@ bar list. If set to a value of ignoredups, lines matching the previous history line are not entered. A value of ignoreboth combines the two options. If - unset, or if set to none (or any other value - than those above), all lines read in interactive mode are - saved on the history list. + unset, or if set to none (the default), all lines + read in interactive mode are saved on the history list. @@ -3312,7 +3311,7 @@ bar to an interactive session of psql will terminate the application. If set to a numeric value, that many EOF characters are ignored before the - application terminates. If the variable is set but has no + application terminates. If the variable is set but not to a numeric value, the default is 10. @@ -3477,6 +3476,16 @@ bar + + VERSION + + + This variable is set at program start-up to + reflect psql's version. It can be unset or changed. + + + + -- cgit v1.2.3