pgsql: Fix behavior of printTable() and friends with externally-invoked - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix behavior of printTable() and friends with externally-invoked
Date
Msg-id E1a4Ghf-00067E-OY@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix behavior of printTable() and friends with externally-invoked pager.

The formatting modes that depend on knowledge of the terminal window width
did not work right when printing a query result that's been fetched in
sections (as a result of FETCH_SIZE).  ExecQueryUsingCursor() would force
use of the pager as soon as there's more than one result section, and then
print.c would see an output file pointer that's not stdout and incorrectly
conclude that the terminal window width isn't relevant.

This has been broken all along for non-expanded "wrapped" output format,
and as of 9.5 the issue affects expanded mode as well.  The problem also
caused "\pset expanded auto" mode to invariably *not* switch to expanded
output in a segmented result, which seems to me to be exactly backwards.

To fix, we need to pass down an "is_pager" flag to inform the print.c
subroutines that some calling level has already replaced stdout with a
pager pipe, so they should (a) not do that again and (b) nonetheless honor
the window size.  (Notably, this makes the first is_pager test in
print_aligned_text() not be dead code anymore.)

This patch is a bit invasive because there are so many existing calls of
printQuery()/printTable(), but fortunately all but a couple can just pass
"false" for the added parameter.

Back-patch to 9.5 but no further.  Given the lack of field complaints,
it's not clear that we should change the behavior in stable branches.
Also, the API change for printQuery()/printTable() might possibly break
third-party code, again something we don't like to do in stable branches.
However, it's not quite too late to do this in 9.5, and with the larger
scope of the problem there, it seems worth doing.

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/375a3b3397487e46c9c607f23db4851eb5bb9ece

Modified Files
--------------
src/bin/psql/common.c        |   11 +++---
src/bin/psql/describe.c      |   69 +++++++++++++++++------------------
src/bin/psql/large_obj.c     |    2 +-
src/bin/psql/print.c         |   83 ++++++++++++++++++++++++++++--------------
src/bin/psql/print.h         |    5 ++-
src/bin/scripts/createlang.c |    2 +-
src/bin/scripts/droplang.c   |    2 +-
7 files changed, 102 insertions(+), 72 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix behavior of printTable() and friends with externally-invoked
Next
From: Tom Lane
Date:
Subject: Re: pgsql: Refactor Perl test code