• Tom Lane's avatar
    Fix behavior of printTable() and friends with externally-invoked pager. · d8ff060e
    Tom Lane authored
    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.
    d8ff060e
print.c 79 KB