summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-01-30 16:37:15 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2017-01-30 16:37:26 -0500
commit511ae628f31b4e791cd5c7836e46cb84dcf145fd (patch)
tree22e592d129edd1004003680bec809ab1c5e67428 /src/test
parent46aae5949f56580281a0f487c785c745d8856a04 (diff)
downloadpostgresql-511ae628f31b4e791cd5c7836e46cb84dcf145fd.tar.gz
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
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/psql.out11
-rw-r--r--src/test/regress/sql/psql.sql8
2 files changed, 18 insertions, 1 deletions
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index 464436ab3b..420825aa56 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -2,6 +2,15 @@
-- Tests for psql features that aren't closely connected to any
-- specific server features
--
+-- \set
+-- fail: invalid name
+\set invalid/name foo
+invalid variable name: "invalid/name"
+-- fail: invalid value for special variable
+\set AUTOCOMMIT foo
+unrecognized value "foo" for "AUTOCOMMIT": boolean expected
+\set FETCH_COUNT foo
+invalid value "foo" for "FETCH_COUNT": integer expected
-- \gset
select 10 as test01, 20 as test02, 'Hello' as test03 \gset pref01_
\echo :pref01_test01 :pref01_test02 :pref01_test03
@@ -9,7 +18,7 @@ select 10 as test01, 20 as test02, 'Hello' as test03 \gset pref01_
-- should fail: bad variable name
select 10 as "bad name"
\gset
-could not set variable "bad name"
+invalid variable name: "bad name"
-- multiple backslash commands in one line
select 1 as x, 2 as y \gset pref01_ \\ \echo :pref01_x
1
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index 900aa7ee1e..79624b9193 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -3,6 +3,14 @@
-- specific server features
--
+-- \set
+
+-- fail: invalid name
+\set invalid/name foo
+-- fail: invalid value for special variable
+\set AUTOCOMMIT foo
+\set FETCH_COUNT foo
+
-- \gset
select 10 as test01, 20 as test02, 'Hello' as test03 \gset pref01_