]> granicus.if.org Git - postgresql/commit
Fix behavior of printTable() and friends with externally-invoked pager.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 2 Dec 2015 23:20:33 +0000 (18:20 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 2 Dec 2015 23:20:41 +0000 (18:20 -0500)
commitd8ff060ecd5fc2dd20021743518d376a11a0bfd8
tree09f40f890ff8fe63c7c6f95aa37ad539f57c7271
parent1caef31d9e550408d0cbc5788a422dcb69736df5
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.
src/bin/psql/common.c
src/bin/psql/describe.c
src/bin/psql/large_obj.c
src/bin/psql/print.c
src/bin/psql/print.h
src/bin/scripts/createlang.c
src/bin/scripts/droplang.c