Re: Fix psql pager selection for wrapped expanded output

From: Erik Wienhold <ewie(at)ewie(dot)name>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Fix psql pager selection for wrapped expanded output
Date: 2026-07-01 14:57:38
Message-ID: a977a633-cff1-425c-861a-5b29e0c17aab@ewie.name
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2026-07-01 09:14 +0200, Chao Li wrote:
> > On Jul 1, 2026, at 04:34, Erik Wienhold <ewie(at)ewie(dot)name> wrote:
> >
> > On 2026-06-12 12:01 +0200, Chao Li wrote:
> >> While testing “[27da1a796] Improve psql's ability to select pager mode
> >> accurately”, I found that the pager doesn’t work for expanded wrapped
> >> mode. However, I realized that this is not a new problem introduced by
> >> 27da1a796, it didn’t work before 27da1a796 either. Instead, with
> >> 27da1a796, we are almost there to make it work.
> >>
> >> 27da1a796 introduces a new helper count_table_lines(), that takes a
> >> per-column-width array. For expanded mode (vertical mode), all columns
> >> use the same data width. So we can simply build such a width_wrap
> >> array, and move IsPagerNeeded() to after dwidth is computed. Then the
> >> pager works in expanded wrapped mode.
> >>
> >> I tested with this procedure (making the terminal small with ~30 rows):
> >> ```
> >> \pset pager on
> >> \pset columns 25
> >> \pset expanded on
> >> \pset format wrapped
> >> select g AS id, 'name_' || g AS name, repeat('x', g * 5) AS payload from generate_series(1, 10) AS g;
> >> ```
> >> See the attached patch for details. I’m not going to add this to the
> >> v19 open items, as it’s not a v19-new bug.
> >
> > The changes to print.c look good to me and it works in manual testing.
>
> Thanks for your review and test.
>
> >
> >> +# With the 80-column pty, the payload wraps to two lines per row.
> >> +# Expanded output also prints one record header per row, plus a trailing
> >> +# blank line, so this produces 11 * 3 + 1 = 34 lines.
> >> +do_command(
> >> + "\\pset expanded on\n\\pset format wrapped\n\\pset columns 80\nSELECT repeat('x',138) AS payload FROM generate_series(1,11);\n",
> >
> > We can do without \pset columns 80 here since the PTY is already set to
> > 80 columns by the test setup on line 82. I'd also change the query to
> > return repeat('x', 80) which is sufficiently long for the wrapping to
> > occur. It's then also clear that this length is related to the PTY
> > width while 138 lacks any meaning IMO.
>
> Agreed and addressed in v2.

Thanks! LGTM.

--
Erik Wienhold

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2026-07-01 15:03:54 Re: The PostgreSQL C Dialect
Previous Message Heikki Linnakangas 2026-07-01 14:54:55 Re: postgres_fdw: fix cumulative stats after imported foreign-table stats