Thread

Commits

  1. psql: Fix expanded aligned output

  1. bugfix - fix broken output in expanded aligned format, when data are too short

    Pavel Stehule <pavel.stehule@gmail.com> — 2026-03-23T19:42:35Z

    Hi
    
    There is a bug in fe_utils
    
    (2026-03-23 20:36:21) postgres=# \pset
    border                   2
    columns                  0
    csv_fieldsep             ','
    display_false            'f'
    display_true             't'
    expanded                 on
    fieldsep                 '|'
    fieldsep_zero            off
    footer                   on
    format                   aligned
    linestyle                unicode
    null                     '∅'
    numericlocale            off
    pager                    1
    pager_min_lines          0
    recordsep                '\n'
    recordsep_zero           off
    tableattr
    title
    tuples_only              off
    unicode_border_linestyle single
    unicode_column_linestyle single
    unicode_header_linestyle double
    xheader_width            full
    
    (2026-03-23 20:36:56) postgres=# select * from foo;
    kuku
    ┌────┬────┐
    │ a  │ b  │
    ╞════╪════╡
    │ 10 │ 20 │
    │ 10 │ 20 │
    └────┴────┘
    (2 rows)
    
    (2026-03-23 20:36:58) postgres=# \x
    Expanded display is on.
    (2026-03-23 20:37:01) postgres=# select * from foo;
    ┌─[ RECORD 1 ]─┐
    │ a │ 10 │
    │ b │ 20 │
    ╞═[ RECORD 2 ]═╡
    │ a │ 10 │
    │ b │ 20 │
    └───┴────┘
    
    the bugfix is really short
    
    pavel@nemesis:~/src/postgresql$ git diff master
    diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
    index 12d969e8666..58a04a902d5 100644
    --- a/src/fe_utils/print.c
    +++ b/src/fe_utils/print.c
    @@ -1445,7 +1445,7 @@ print_aligned_vertical(const printTableContent *cont,
        /*
         * Calculate available width for data in wrapped mode
         */
    -   if (cont->opt->format == PRINT_WRAPPED)
    +   if (cont->opt->format == PRINT_WRAPPED || cont->opt->format ==
    PRINT_ALIGNED)
        {
            unsigned int swidth,
                        rwidth = 0,
    
    after fix:
    
    (2026-03-23 20:40:11) postgres=# \x
    Expanded display is on.
    (2026-03-23 20:40:13) postgres=# select * from foo;
    ┌─[ RECORD 1 ]─┐
    │ a │ 10       │
    │ b │ 20       │
    ╞═[ RECORD 2 ]═╡
    │ a │ 10       │
    │ b │ 20       │
    └───┴──────────┘
    
    Regards
    
    Pavel
    
  2. Re: bugfix - fix broken output in expanded aligned format, when data are too short

    Pavel Stehule <pavel.stehule@gmail.com> — 2026-03-24T05:46:34Z

    Hi
    
    new version
    
    * fixed unwanted forcing to wrapped mode
    * regress test
    
    Regards
    
    Pavel
    
  3. Re: bugfix - fix broken output in expanded aligned format, when data are too short

    Chao Li <li.evan.chao@gmail.com> — 2026-03-24T06:12:18Z

    
    > On Mar 24, 2026, at 13:46, Pavel Stehule <pavel.stehule@gmail.com> wrote:
    > 
    > Hi
    > 
    > new version
    > 
    > * fixed unwanted forcing to wrapped mode
    > * regress test
    > 
    > Regards
    > 
    > Pavel
    > <v20260324-1-0001-The-output-of-thin-table-is-broken-in-expanded-mode-.patch>
    
    Thanks for the fix. The patch overall looks good to me. A couple of small comments:
    
    1
    ```
     	/*
     	 * Calculate available width for data in wrapped mode
     	 */
    -	if (cont->opt->format == PRINT_WRAPPED)
    +	if (cont->opt->format == PRINT_WRAPPED || cont->opt->format == PRINT_ALIGNED)
    ```
    
    Since the condition has been updated, I think the comment above should be adjusted as well.
    
    2
    ```
    +-- the output in expanded mode is shorter than header
    +\pset border 2
    +\pset expanded on
    +create table psql_short_tab(a int, b int);
    +insert into psql_short_tab values(10,20),(30,40);
    +\pset format aligned
    +select * from psql_short_tab;
    +\pset format wrapped
    +select * from psql_short_tab;
    +drop table psql_short_tab;
    +
    ```
    
    After this test, does it make sense to turn expanded mode off explicitly, in case it affects following tests? Today the next test happens to reset it, but maybe tomorrow a new test gets added before that point.
    
    Best regards,
    --
    Chao Li (Evan)
    HighGo Software Co., Ltd.
    https://www.highgo.com/
    
    
    
    
    
    
    
    
  4. Re: bugfix - fix broken output in expanded aligned format, when data are too short

    Pavel Stehule <pavel.stehule@gmail.com> — 2026-03-24T06:31:11Z

    út 24. 3. 2026 v 7:12 odesílatel Chao Li <li.evan.chao@gmail.com> napsal:
    
    >
    >
    > > On Mar 24, 2026, at 13:46, Pavel Stehule <pavel.stehule@gmail.com>
    > wrote:
    > >
    > > Hi
    > >
    > > new version
    > >
    > > * fixed unwanted forcing to wrapped mode
    > > * regress test
    > >
    > > Regards
    > >
    > > Pavel
    > >
    > <v20260324-1-0001-The-output-of-thin-table-is-broken-in-expanded-mode-.patch>
    >
    > Thanks for the fix. The patch overall looks good to me. A couple of small
    > comments:
    >
    > 1
    > ```
    >         /*
    >          * Calculate available width for data in wrapped mode
    >          */
    > -       if (cont->opt->format == PRINT_WRAPPED)
    > +       if (cont->opt->format == PRINT_WRAPPED || cont->opt->format ==
    > PRINT_ALIGNED)
    > ```
    >
    > Since the condition has been updated, I think the comment above should be
    > adjusted as well.
    >
    
    done
    
    pavel@nemesis:~/src/postgresql$ git diff
    diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
    index 7d7eb7dd041..dbfe437bc4c 100644
    --- a/src/fe_utils/print.c
    +++ b/src/fe_utils/print.c
    @@ -1443,7 +1443,8 @@ print_aligned_vertical(const printTableContent *cont,
        }
    
        /*
    -    * Calculate available width for data in wrapped mode
    +    * Calculate available width for data in wrapped mode or minimal width
    +    * in aligned mode
         */
        if (cont->opt->format == PRINT_WRAPPED || cont->opt->format ==
    PRINT_ALIGNED)
        {
    
    
    
    >
    > 2
    > ```
    > +-- the output in expanded mode is shorter than header
    > +\pset border 2
    > +\pset expanded on
    > +create table psql_short_tab(a int, b int);
    > +insert into psql_short_tab values(10,20),(30,40);
    > +\pset format aligned
    > +select * from psql_short_tab;
    > +\pset format wrapped
    > +select * from psql_short_tab;
    > +drop table psql_short_tab;
    > +
    > ```
    >
    > After this test, does it make sense to turn expanded mode off explicitly,
    > in case it affects following tests? Today the next test happens to reset
    > it, but maybe tomorrow a new test gets added before that point.
    >
    
    There is no default pset setting in psql.sql. Following test has its own
    setting. Generally this is the responsibility to every test to set the
    environment how it is necessary. Maybe I am wrong, but I see, so only
    database objects and prepared queries are cleaned there. There is not
    problem to write \pset border 1 \pset expanded off, but following tests
    starts with \pset expanded off and this can be little bit messy and
    redundant
    
    Thank you for check
    
    Regards
    
    Pavel
    
    
    >
    > Best regards,
    > --
    > Chao Li (Evan)
    > HighGo Software Co., Ltd.
    > https://www.highgo.com/
    >
    >
    >
    >
    >
    
  5. Re: bugfix - fix broken output in expanded aligned format, when data are too short

    Chao Li <li.evan.chao@gmail.com> — 2026-03-24T07:00:30Z

    
    > On Mar 24, 2026, at 14:31, Pavel Stehule <pavel.stehule@gmail.com> wrote:
    > 
    > 
    > 
    > út 24. 3. 2026 v 7:12 odesílatel Chao Li <li.evan.chao@gmail.com> napsal:
    > 
    > 
    > > On Mar 24, 2026, at 13:46, Pavel Stehule <pavel.stehule@gmail.com> wrote:
    > > 
    > > Hi
    > > 
    > > new version
    > > 
    > > * fixed unwanted forcing to wrapped mode
    > > * regress test
    > > 
    > > Regards
    > > 
    > > Pavel
    > > <v20260324-1-0001-The-output-of-thin-table-is-broken-in-expanded-mode-.patch>
    > 
    > Thanks for the fix. The patch overall looks good to me. A couple of small comments:
    > 
    > 1
    > ```
    >         /*
    >          * Calculate available width for data in wrapped mode
    >          */
    > -       if (cont->opt->format == PRINT_WRAPPED)
    > +       if (cont->opt->format == PRINT_WRAPPED || cont->opt->format == PRINT_ALIGNED)
    > ```
    > 
    > Since the condition has been updated, I think the comment above should be adjusted as well.
    > 
    > done
    > 
    > pavel@nemesis:~/src/postgresql$ git diff
    > diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
    > index 7d7eb7dd041..dbfe437bc4c 100644
    > --- a/src/fe_utils/print.c
    > +++ b/src/fe_utils/print.c
    > @@ -1443,7 +1443,8 @@ print_aligned_vertical(const printTableContent *cont,
    >     }
    >  
    >     /*
    > -    * Calculate available width for data in wrapped mode
    > +    * Calculate available width for data in wrapped mode or minimal width
    > +    * in aligned mode
    >      */
    >     if (cont->opt->format == PRINT_WRAPPED || cont->opt->format == PRINT_ALIGNED)
    >     {
    > 
    >  
    > 2
    > ```
    > +-- the output in expanded mode is shorter than header
    > +\pset border 2
    > +\pset expanded on
    > +create table psql_short_tab(a int, b int);
    > +insert into psql_short_tab values(10,20),(30,40);
    > +\pset format aligned
    > +select * from psql_short_tab;
    > +\pset format wrapped
    > +select * from psql_short_tab;
    > +drop table psql_short_tab;
    > +
    > ```
    > 
    > After this test, does it make sense to turn expanded mode off explicitly, in case it affects following tests? Today the next test happens to reset it, but maybe tomorrow a new test gets added before that point.
    > 
    > There is no default pset setting in psql.sql. Following test has its own setting. Generally this is the responsibility to every test to set the environment how it is necessary. Maybe I am wrong, but I see, so only database objects and prepared queries are cleaned there. There is not problem to write \pset border 1 \pset expanded off, but following tests starts with \pset expanded off and this can be little bit messy and redundant 
    > 
    > Thank you for check
    > 
    > Regards
    > 
    > Pavel
    >  
    > Best regards,
    > --
    > Chao Li (Evan)
    > HighGo Software Co., Ltd.
    > https://www.highgo.com/
    > 
    > 
    > 
    > 
    > <v20260324-2-0001-The-output-of-thin-table-is-broken-in-expanded-mode-.patch>
    
    LGTM.
    
    Best regards,
    --
    Chao Li (Evan)
    HighGo Software Co., Ltd.
    https://www.highgo.com/
    
    
    
    
    
    
    
    
  6. Re: bugfix - fix broken output in expanded aligned format, when data are too short

    getiancheng <getiancheng_2012@163.com> — 2026-03-24T07:17:09Z

    
    
    
    ---- Replied Message ----
    | From | Chao Li<li.evan.chao@gmail.com> |
    | Date | 3/24/2026 15:01 |
    | To | Pavel Stehule<pavel.stehule@gmail.com> |
    | Cc | PostgreSQL Hackers<pgsql-hackers@lists.postgresql.org> |
    | Subject | Re: bugfix - fix broken output in expanded aligned format, when data are too short |
    
    
    On Mar 24, 2026, at 14:31, Pavel Stehule <pavel.stehule@gmail.com> wrote:
    
    
    
     út 24. 3. 2026 v 7:12 odesílatel Chao Li <li.evan.chao@gmail.com> napsal:
    
    
    On Mar 24, 2026, at 13:46, Pavel Stehule <pavel.stehule@gmail.com> wrote:
    
     Hi
    
     new version
    
     * fixed unwanted forcing to wrapped mode
     * regress test
    
     Regards
    
     Pavel
     <v20260324-1-0001-The-output-of-thin-table-is-broken-in-expanded-mode-.patch>
    
     Thanks for the fix. The patch overall looks good to me. A couple of small comments:
    
     1
     ```
             /*
              * Calculate available width for data in wrapped mode
              */
     -       if (cont->opt->format == PRINT_WRAPPED)
     +       if (cont->opt->format == PRINT_WRAPPED || cont->opt->format == PRINT_ALIGNED)
     ```
    
     Since the condition has been updated, I think the comment above should be adjusted as well.
    
     done
    
     pavel@nemesis:~/src/postgresql$ git diff
     diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
     index 7d7eb7dd041..dbfe437bc4c 100644
     --- a/src/fe_utils/print.c
     +++ b/src/fe_utils/print.c
     @@ -1443,7 +1443,8 @@ print_aligned_vertical(const printTableContent *cont,
         }
    
         /*
     -    * Calculate available width for data in wrapped mode
     +    * Calculate available width for data in wrapped mode or minimal width
     +    * in aligned mode
          */
         if (cont->opt->format == PRINT_WRAPPED || cont->opt->format == PRINT_ALIGNED)
         {
    
    
     2
     ```
     +-- the output in expanded mode is shorter than header
     +\pset border 2
     +\pset expanded on
     +create table psql_short_tab(a int, b int);
     +insert into psql_short_tab values(10,20),(30,40);
     +\pset format aligned
     +select * from psql_short_tab;
     +\pset format wrapped
     +select * from psql_short_tab;
     +drop table psql_short_tab;
     +
     ```
    
     After this test, does it make sense to turn expanded mode off explicitly, in case it affects following tests? Today the next test happens to reset it, but maybe tomorrow a new test gets added before that point.
    
     There is no default pset setting in psql.sql. Following test has its own setting. Generally this is the responsibility to every test to set the environment how it is necessary. Maybe I am wrong, but I see, so only database objects and prepared queries are cleaned there. There is not problem to write \pset border 1 \pset expanded off, but following tests starts with \pset expanded off and this can be little bit messy and redundant 
    
     Thank you for check
    
     Regards
    
     Pavel
    
     Best regards,
     --
     Chao Li (Evan)
     HighGo Software Co., Ltd.
     https://www.highgo.com/
    
    
    
    
     <v20260324-2-0001-The-output-of-thin-table-is-broken-in-expanded-mode-.patch>
    
    LGTM.
    
    Best regards,
    --
    Chao Li (Evan)
    HighGo Software Co., Ltd.
    https://www.highgo.com/
    
    
    Hi,
    Overall looks good to me. Only nitpick is that, in the commit message, "thin table" sounds a little unusual, maybe "narrow table".
    
    
    
    
    Best regards,
    Tiancheng Ge
    
    
    
  7. Re: bugfix - fix broken output in expanded aligned format, when data are too short

    Pavel Stehule <pavel.stehule@gmail.com> — 2026-03-24T07:23:01Z

    út 24. 3. 2026 v 8:17 odesílatel getiancheng <getiancheng_2012@163.com>
    napsal:
    
    >
    >
    > ---- Replied Message ----
    > From Chao Li<li.evan.chao@gmail.com> <li.evan.chao@gmail.com>
    > Date 3/24/2026 15:01
    > To Pavel Stehule<pavel.stehule@gmail.com> <pavel.stehule@gmail.com>
    > Cc PostgreSQL Hackers<pgsql-hackers@lists.postgresql.org>
    > <pgsql-hackers@lists.postgresql.org>
    > Subject Re: bugfix - fix broken output in expanded aligned format, when
    > data are too short
    >
    >
    >
    > On Mar 24, 2026, at 14:31, Pavel Stehule <pavel.stehule@gmail.com> wrote:
    >
    >
    >
    >  út 24. 3. 2026 v 7:12 odesílatel Chao Li <li.evan.chao@gmail.com> napsal:
    >
    >
    >  On Mar 24, 2026, at 13:46, Pavel Stehule <pavel.stehule@gmail.com> wrote:
    >
    >  Hi
    >
    >  new version
    >
    >  * fixed unwanted forcing to wrapped mode
    >  * regress test
    >
    >  Regards
    >
    >  Pavel
    >  <v20260324-1-0001-The-output-of-thin-table-is-broken-in-expanded-mode-.patch>
    >
    >
    >  Thanks for the fix. The patch overall looks good to me. A couple of small comments:
    >
    >  1
    >  ```
    >          /*
    >           * Calculate available width for data in wrapped mode
    >           */
    >  -       if (cont->opt->format == PRINT_WRAPPED)
    >  +       if (cont->opt->format == PRINT_WRAPPED || cont->opt->format == PRINT_ALIGNED)
    >  ```
    >
    >  Since the condition has been updated, I think the comment above should be adjusted as well.
    >
    >  done
    >
    >  pavel@nemesis:~/src/postgresql$ git diff
    >  diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
    >  index 7d7eb7dd041..dbfe437bc4c 100644
    >  --- a/src/fe_utils/print.c
    >  +++ b/src/fe_utils/print.c
    >  @@ -1443,7 +1443,8 @@ print_aligned_vertical(const printTableContent *cont,
    >      }
    >
    >      /*
    >  -    * Calculate available width for data in wrapped mode
    >  +    * Calculate available width for data in wrapped mode or minimal width
    >  +    * in aligned mode
    >       */
    >      if (cont->opt->format == PRINT_WRAPPED || cont->opt->format == PRINT_ALIGNED)
    >      {
    >
    >
    >  2
    >  ```
    >  +-- the output in expanded mode is shorter than header
    >  +\pset border 2
    >  +\pset expanded on
    >  +create table psql_short_tab(a int, b int);
    >  +insert into psql_short_tab values(10,20),(30,40);
    >  +\pset format aligned
    >  +select * from psql_short_tab;
    >  +\pset format wrapped
    >  +select * from psql_short_tab;
    >  +drop table psql_short_tab;
    >  +
    >  ```
    >
    >  After this test, does it make sense to turn expanded mode off explicitly, in case it affects following tests? Today the next test happens to reset it, but maybe tomorrow a new test gets added before that point.
    >
    >  There is no default pset setting in psql.sql. Following test has its own setting. Generally this is the responsibility to every test to set the environment how it is necessary. Maybe I am wrong, but I see, so only database objects and prepared queries are cleaned there. There is not problem to write \pset border 1 \pset expanded off, but following tests starts with \pset expanded off and this can be little bit messy and redundant
    >
    >  Thank you for check
    >
    >  Regards
    >
    >  Pavel
    >
    >  Best regards,
    >  --
    >  Chao Li (Evan)
    >  HighGo Software Co., Ltd.
    >  https://www.highgo.com/
    >
    >
    >
    >
    >  <v20260324-2-0001-The-output-of-thin-table-is-broken-in-expanded-mode-.patch>
    >
    >
    > LGTM.
    >
    > Best regards,
    > --
    > Chao Li (Evan)
    > HighGo Software Co., Ltd.
    > https://www.highgo.com/
    >
    >
    > Hi,
    >
    > Overall looks good to me. Only nitpick is that, in the commit message, "thin table" sounds a little unusual, maybe "narrow table".
    >
    >
    changed in attached version
    
    Thank you for check
    
    Regards
    
    Pavel
    
    >
    >
    > Best regards,
    > Tiancheng Ge
    >
    >
    >
    
  8. Re: bugfix - fix broken output in expanded aligned format, when data are too short

    Pavel Stehule <pavel.stehule@gmail.com> — 2026-05-26T06:22:17Z

    Hi
    
    fresh rebase
    
    Regards
    
    Pavel
    
  9. Re: bugfix - fix broken output in expanded aligned format, when data are too short

    Pavel Stehule <pavel.stehule@gmail.com> — 2026-06-07T08:39:21Z

    Hi
    
    only rebase
    
    Regards
    
    Pavel
    
  10. Re: bugfix - fix broken output in expanded aligned format, when data are too short

    Michael Paquier <michael@paquier.xyz> — 2026-06-08T01:36:29Z

    On Sun, Jun 07, 2026 at 10:39:21AM +0200, Pavel Stehule wrote:
    > only rebase
    
    The patch has been lying around for a couple of months, and as far as
    I can see it looks incorrect in the way this calculates the column
    width.  Short of some adjustments for the description of the test and
    the comment you have changed, I'll double-check the whole.
    
    Thanks for the report and the patch.
    --
    Michael
    
  11. Re: bugfix - fix broken output in expanded aligned format, when data are too short

    Michael Paquier <michael@paquier.xyz> — 2026-06-08T05:45:40Z

    On Mon, Jun 08, 2026 at 10:36:29AM +0900, Michael Paquier wrote:
    > Thanks for the report and the patch.
    
    Done as of 3d0d6741d810 & friends.
    --
    Michael
    
  12. Re: bugfix - fix broken output in expanded aligned format, when data are too short

    Pavel Stehule <pavel.stehule@gmail.com> — 2026-06-08T06:39:06Z

    Dne po 8. 6. 2026 7:45 uživatel Michael Paquier <michael@paquier.xyz>
    napsal:
    
    > On Mon, Jun 08, 2026 at 10:36:29AM +0900, Michael Paquier wrote:
    > > Thanks for the report and the patch.
    >
    > Done as of 3d0d6741d810 & friends.
    >
    
    Thank you
    
    Pavel
    
    > --
    > Michael
    >