Here's a patch to fix the pager setup when printing tables with large footers, e.g., long view definitions.
For testing create a view with many columns (50 in this example): select 'create view longview as select ' || string_agg('1 f' || s, ', ') from generate_series(1, 50) s \gexec Then describe the view with verbose output to also print its definition in the table footer: \d+ longview Without the patch, no pager is used when the terminal can display 55 or more lines (check with `stty size`). Below 55 available lines the pager is always used because the table itself requires 54 lines (50 view columns + 3 header lines + 1 "View definition" footer line). With the patch applied, the lines of the view definition also count towards the line total and the pager is used when more than 54 lines are available. -- Erik Wienhold
>From df68e0ca50d982e3dc1dbc39d7868dcbfd011132 Mon Sep 17 00:00:00 2001 From: Erik Wienhold <e...@ewie.name> Date: Wed, 7 May 2025 03:43:46 +0200 Subject: [PATCH v1] psql: Count all table footer lines in pager setup Until now every table footer was counted as a single line when determining if the pager is needed. This fails to trigger the pager when describing a view with a long definition using command \d+. Fix that by counting the actual lines of the footer text. --- src/fe_utils/print.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c index 4af0f32f2fc..accb12145da 100644 --- a/src/fe_utils/print.c +++ b/src/fe_utils/print.c @@ -3416,12 +3416,13 @@ IsPagerNeeded(const printTableContent *cont, int extra_lines, bool expanded, { printTableFooter *f; - /* - * FIXME -- this is slightly bogus: it counts the number of - * footers, not the number of lines in them. - */ - for (f = cont->footers; f; f = f->next) - lines++; + for (f = cont->footers; f; f = f->next) { + int f_lines; + + pg_wcssize((const unsigned char *) f->data, strlen(f->data), + cont->opt->encoding, NULL, &f_lines, NULL); + lines += f_lines; + } } *fout = PageOutput(lines + extra_lines, cont->opt); -- 2.50.1