]> granicus.if.org Git - postgresql/commit
Improve psql's behavior for \set and \unset of its control variables.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 1 Feb 2017 16:02:40 +0000 (11:02 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 1 Feb 2017 16:02:40 +0000 (11:02 -0500)
commit86322dc7e013b4062393dcbb74043db003e23ec5
treeb209a1ef6c679a3e53b92f146189b0a7cfe92343
parentdbd69118c05d73969a1bd52ead6702c6e40b0fee
Improve psql's behavior for \set and \unset of its control variables.

This commit improves on the results of commit 511ae628f in two ways:

1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable.  We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable.  However, now this
case will result in actually setting FOO to "on", not an empty string.

2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.

In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.

The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one.  We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.

Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.

This patch also includes some minor cleanup that should have been in
511ae628f but was missed.

Patch by me, but it owes a lot to discussions with Daniel Vérité.

Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/startup.c
src/bin/psql/variables.c
src/bin/psql/variables.h
src/test/regress/expected/psql.out
src/test/regress/sql/psql.sql