public inbox for [email protected]  
help / color / mirror / Atom feed
bugfix - fix broken output in expanded aligned format, when data are too short
10+ messages / 3 participants
[nested] [flat]

* bugfix - fix broken output in expanded aligned format, when data are too short
@ 2026-03-23 19:42  Pavel Stehule <[email protected]>
  0 siblings, 1 reply; 10+ messages in thread

From: Pavel Stehule @ 2026-03-23 19:42 UTC (permalink / raw)
  To: PostgreSQL Hackers <[email protected]>

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


Attachments:

  [text/x-patch] 0001-fix-expended-aligned-format.patch (759B, 3-0001-fix-expended-aligned-format.patch)
  download | inline diff:
From 131261620f35997be1cf2b4726577c2c284335d2 Mon Sep 17 00:00:00 2001
From: "[email protected]" <[email protected]>
Date: Mon, 23 Mar 2026 20:39:31 +0100
Subject: [PATCH] fix expended aligned format

---
 src/fe_utils/print.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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,
-- 
2.53.0



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: bugfix - fix broken output in expanded aligned format, when data are too short
@ 2026-03-24 05:46  Pavel Stehule <[email protected]>
  parent: Pavel Stehule <[email protected]>
  0 siblings, 1 reply; 10+ messages in thread

From: Pavel Stehule @ 2026-03-24 05:46 UTC (permalink / raw)
  To: PostgreSQL Hackers <[email protected]>

Hi

new version

* fixed unwanted forcing to wrapped mode
* regress test

Regards

Pavel


Attachments:

  [text/x-patch] v20260324-1-0001-The-output-of-thin-table-is-broken-in-expanded-mode-.patch (2.8K, 3-v20260324-1-0001-The-output-of-thin-table-is-broken-in-expanded-mode-.patch)
  download | inline diff:
From 8894b8720b0c89f97b3f439c5ae0bc957d550e17 Mon Sep 17 00:00:00 2001
From: "[email protected]" <[email protected]>
Date: Tue, 24 Mar 2026 06:42:18 +0100
Subject: [PATCH] The output of thin table is broken in expanded mode (when
 header is wider than row) and when aligned mode is used. The wrapped mode is
 ok. This patch fixes this issue.

---
 src/fe_utils/print.c               |  4 ++--
 src/test/regress/expected/psql.out | 26 ++++++++++++++++++++++++++
 src/test/regress/sql/psql.sql      | 11 +++++++++++
 3 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
index 12d969e8666..7d7eb7dd041 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,
@@ -1517,7 +1517,7 @@ print_aligned_vertical(const printTableContent *cont,
 			if (width < rwidth)
 				width = rwidth;
 
-			if (output_columns > 0)
+			if (cont->opt->format == PRINT_WRAPPED && output_columns > 0)
 			{
 				unsigned int min_width;
 
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index c8f3932edf0..dc44219631e 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -2854,6 +2854,32 @@ execute q;
 +------------------+-------------------+
 
 deallocate q;
+-- 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;
++-[ RECORD 1 ]-+
+| a | 10       |
+| b | 20       |
++-[ RECORD 2 ]-+
+| a | 30       |
+| b | 40       |
++---+----------+
+
+\pset format wrapped
+select * from psql_short_tab;
++-[ RECORD 1 ]-+
+| a | 10       |
+| b | 20       |
++-[ RECORD 2 ]-+
+| a | 30       |
+| b | 40       |
++---+----------+
+
+drop table psql_short_tab;
 \pset linestyle ascii
 \pset border 1
 -- support table for output-format tests (useful to create a footer)
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index dcdbd4fc020..b03a61f8656 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -499,6 +499,17 @@ execute q;
 
 deallocate q;
 
+-- 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;
+
 \pset linestyle ascii
 \pset border 1
 
-- 
2.53.0



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: bugfix - fix broken output in expanded aligned format, when data are too short
@ 2026-03-24 06:12  Chao Li <[email protected]>
  parent: Pavel Stehule <[email protected]>
  0 siblings, 1 reply; 10+ messages in thread

From: Chao Li @ 2026-03-24 06:12 UTC (permalink / raw)
  To: Pavel Stehule <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>



> On Mar 24, 2026, at 13:46, Pavel Stehule <[email protected]> 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/









^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: bugfix - fix broken output in expanded aligned format, when data are too short
@ 2026-03-24 06:31  Pavel Stehule <[email protected]>
  parent: Chao Li <[email protected]>
  0 siblings, 1 reply; 10+ messages in thread

From: Pavel Stehule @ 2026-03-24 06:31 UTC (permalink / raw)
  To: Chao Li <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>

út 24. 3. 2026 v 7:12 odesílatel Chao Li <[email protected]> napsal:

>
>
> > On Mar 24, 2026, at 13:46, Pavel Stehule <[email protected]>
> 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/
>
>
>
>
>


Attachments:

  [text/x-patch] v20260324-2-0001-The-output-of-thin-table-is-broken-in-expanded-mode-.patch (2.9K, 3-v20260324-2-0001-The-output-of-thin-table-is-broken-in-expanded-mode-.patch)
  download | inline diff:
From b46c5393e674f11515fe7d025effa48dc4aaf4d8 Mon Sep 17 00:00:00 2001
From: "[email protected]" <[email protected]>
Date: Tue, 24 Mar 2026 06:42:18 +0100
Subject: [PATCH] The output of thin table is broken in expanded mode (when
 header is wider than row) and when aligned mode is used. The wrapped mode is
 ok. This patch fixes this issue.

---
 src/fe_utils/print.c               |  7 ++++---
 src/test/regress/expected/psql.out | 26 ++++++++++++++++++++++++++
 src/test/regress/sql/psql.sql      | 11 +++++++++++
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
index 12d969e8666..dbfe437bc4c 100644
--- a/src/fe_utils/print.c
+++ b/src/fe_utils/print.c
@@ -1443,9 +1443,10 @@ 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)
+	if (cont->opt->format == PRINT_WRAPPED || cont->opt->format == PRINT_ALIGNED)
 	{
 		unsigned int swidth,
 					rwidth = 0,
@@ -1517,7 +1518,7 @@ print_aligned_vertical(const printTableContent *cont,
 			if (width < rwidth)
 				width = rwidth;
 
-			if (output_columns > 0)
+			if (cont->opt->format == PRINT_WRAPPED && output_columns > 0)
 			{
 				unsigned int min_width;
 
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index c8f3932edf0..dc44219631e 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -2854,6 +2854,32 @@ execute q;
 +------------------+-------------------+
 
 deallocate q;
+-- 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;
++-[ RECORD 1 ]-+
+| a | 10       |
+| b | 20       |
++-[ RECORD 2 ]-+
+| a | 30       |
+| b | 40       |
++---+----------+
+
+\pset format wrapped
+select * from psql_short_tab;
++-[ RECORD 1 ]-+
+| a | 10       |
+| b | 20       |
++-[ RECORD 2 ]-+
+| a | 30       |
+| b | 40       |
++---+----------+
+
+drop table psql_short_tab;
 \pset linestyle ascii
 \pset border 1
 -- support table for output-format tests (useful to create a footer)
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index dcdbd4fc020..b03a61f8656 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -499,6 +499,17 @@ execute q;
 
 deallocate q;
 
+-- 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;
+
 \pset linestyle ascii
 \pset border 1
 
-- 
2.53.0



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: bugfix - fix broken output in expanded aligned format, when data are too short
@ 2026-03-24 07:23  Pavel Stehule <[email protected]>
  parent: Pavel Stehule <[email protected]>
  0 siblings, 1 reply; 10+ messages in thread

From: Pavel Stehule @ 2026-03-24 07:23 UTC (permalink / raw)
  To: getiancheng <[email protected]>; +Cc: Chao Li <[email protected]>; PostgreSQL Hackers <[email protected]>

út 24. 3. 2026 v 8:17 odesílatel getiancheng <[email protected]>
napsal:

>
>
> ---- Replied Message ----
> From Chao Li<[email protected]> <[email protected]>
> Date 3/24/2026 15:01
> To Pavel Stehule<[email protected]> <[email protected]>
> Cc PostgreSQL Hackers<[email protected]>
> <[email protected]>
> Subject Re: bugfix - fix broken output in expanded aligned format, when
> data are too short
>
>
>
> On Mar 24, 2026, at 14:31, Pavel Stehule <[email protected]> wrote:
>
>
>
>  út 24. 3. 2026 v 7:12 odesílatel Chao Li <[email protected]> napsal:
>
>
>  On Mar 24, 2026, at 13:46, Pavel Stehule <[email protected]> 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
>
>
>


Attachments:

  [text/x-patch] v20260324-3-0001-The-output-of-narrow-table-is-broken-in-expanded-mod.patch (2.9K, 3-v20260324-3-0001-The-output-of-narrow-table-is-broken-in-expanded-mod.patch)
  download | inline diff:
From ec2048128dfd41a1a53e73121dc678ebeae344a8 Mon Sep 17 00:00:00 2001
From: "[email protected]" <[email protected]>
Date: Tue, 24 Mar 2026 06:42:18 +0100
Subject: [PATCH] The output of narrow table is broken in expanded mode (when
 header is wider than row) and when aligned mode is used. The wrapped mode is
 ok. This patch fixes this issue.

---
 src/fe_utils/print.c               |  7 ++++---
 src/test/regress/expected/psql.out | 26 ++++++++++++++++++++++++++
 src/test/regress/sql/psql.sql      | 11 +++++++++++
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
index 12d969e8666..dbfe437bc4c 100644
--- a/src/fe_utils/print.c
+++ b/src/fe_utils/print.c
@@ -1443,9 +1443,10 @@ 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)
+	if (cont->opt->format == PRINT_WRAPPED || cont->opt->format == PRINT_ALIGNED)
 	{
 		unsigned int swidth,
 					rwidth = 0,
@@ -1517,7 +1518,7 @@ print_aligned_vertical(const printTableContent *cont,
 			if (width < rwidth)
 				width = rwidth;
 
-			if (output_columns > 0)
+			if (cont->opt->format == PRINT_WRAPPED && output_columns > 0)
 			{
 				unsigned int min_width;
 
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index c8f3932edf0..dc44219631e 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -2854,6 +2854,32 @@ execute q;
 +------------------+-------------------+
 
 deallocate q;
+-- 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;
++-[ RECORD 1 ]-+
+| a | 10       |
+| b | 20       |
++-[ RECORD 2 ]-+
+| a | 30       |
+| b | 40       |
++---+----------+
+
+\pset format wrapped
+select * from psql_short_tab;
++-[ RECORD 1 ]-+
+| a | 10       |
+| b | 20       |
++-[ RECORD 2 ]-+
+| a | 30       |
+| b | 40       |
++---+----------+
+
+drop table psql_short_tab;
 \pset linestyle ascii
 \pset border 1
 -- support table for output-format tests (useful to create a footer)
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index dcdbd4fc020..b03a61f8656 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -499,6 +499,17 @@ execute q;
 
 deallocate q;
 
+-- 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;
+
 \pset linestyle ascii
 \pset border 1
 
-- 
2.53.0



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: bugfix - fix broken output in expanded aligned format, when data are too short
@ 2026-05-26 06:22  Pavel Stehule <[email protected]>
  parent: Pavel Stehule <[email protected]>
  0 siblings, 1 reply; 10+ messages in thread

From: Pavel Stehule @ 2026-05-26 06:22 UTC (permalink / raw)
  To: getiancheng <[email protected]>; +Cc: Chao Li <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi

fresh rebase

Regards

Pavel


Attachments:

  [text/x-patch] 0001-The-output-of-narrow-table-is-broken-in-expanded-mod.patch (2.9K, 3-0001-The-output-of-narrow-table-is-broken-in-expanded-mod.patch)
  download | inline diff:
From d99d82117f294329947240be4023943370220ca0 Mon Sep 17 00:00:00 2001
From: "[email protected]" <[email protected]>
Date: Tue, 24 Mar 2026 06:42:18 +0100
Subject: [PATCH] The output of narrow table is broken in expanded mode (when
 header is wider than row) and when aligned mode is used. The wrapped mode is
 ok. This patch fixes this issue.

---
 src/fe_utils/print.c               |  7 ++++---
 src/test/regress/expected/psql.out | 26 ++++++++++++++++++++++++++
 src/test/regress/sql/psql.sql      | 11 +++++++++++
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
index f2dd52003c1..a5e64cb18fb 100644
--- a/src/fe_utils/print.c
+++ b/src/fe_utils/print.c
@@ -1443,9 +1443,10 @@ 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)
+	if (cont->opt->format == PRINT_WRAPPED || cont->opt->format == PRINT_ALIGNED)
 	{
 		unsigned int swidth,
 					rwidth = 0,
@@ -1517,7 +1518,7 @@ print_aligned_vertical(const printTableContent *cont,
 			if (width < rwidth)
 				width = rwidth;
 
-			if (output_columns > 0)
+			if (cont->opt->format == PRINT_WRAPPED && output_columns > 0)
 			{
 				unsigned int min_width;
 
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index c8f3932edf0..dc44219631e 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -2854,6 +2854,32 @@ execute q;
 +------------------+-------------------+
 
 deallocate q;
+-- 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;
++-[ RECORD 1 ]-+
+| a | 10       |
+| b | 20       |
++-[ RECORD 2 ]-+
+| a | 30       |
+| b | 40       |
++---+----------+
+
+\pset format wrapped
+select * from psql_short_tab;
++-[ RECORD 1 ]-+
+| a | 10       |
+| b | 20       |
++-[ RECORD 2 ]-+
+| a | 30       |
+| b | 40       |
++---+----------+
+
+drop table psql_short_tab;
 \pset linestyle ascii
 \pset border 1
 -- support table for output-format tests (useful to create a footer)
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index dcdbd4fc020..b03a61f8656 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -499,6 +499,17 @@ execute q;
 
 deallocate q;
 
+-- 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;
+
 \pset linestyle ascii
 \pset border 1
 
-- 
2.54.0



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: bugfix - fix broken output in expanded aligned format, when data are too short
@ 2026-06-07 08:39  Pavel Stehule <[email protected]>
  parent: Pavel Stehule <[email protected]>
  0 siblings, 1 reply; 10+ messages in thread

From: Pavel Stehule @ 2026-06-07 08:39 UTC (permalink / raw)
  To: getiancheng <[email protected]>; +Cc: Chao Li <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi

only rebase

Regards

Pavel


Attachments:

  [text/x-patch] v20260607-0001-The-output-of-narrow-table-is-broken-in-expanded-mod.patch (2.9K, 3-v20260607-0001-The-output-of-narrow-table-is-broken-in-expanded-mod.patch)
  download | inline diff:
From 38b7d7d4eeed977e66b9f1ee7e8a3150f6bf6f3e Mon Sep 17 00:00:00 2001
From: "[email protected]" <[email protected]>
Date: Tue, 24 Mar 2026 06:42:18 +0100
Subject: [PATCH] The output of narrow table is broken in expanded mode (when
 header is wider than row) and when aligned mode is used. The wrapped mode is
 ok. This patch fixes this issue.

---
 src/fe_utils/print.c               |  7 ++++---
 src/test/regress/expected/psql.out | 26 ++++++++++++++++++++++++++
 src/test/regress/sql/psql.sql      | 11 +++++++++++
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
index f2dd52003c1..a5e64cb18fb 100644
--- a/src/fe_utils/print.c
+++ b/src/fe_utils/print.c
@@ -1443,9 +1443,10 @@ 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)
+	if (cont->opt->format == PRINT_WRAPPED || cont->opt->format == PRINT_ALIGNED)
 	{
 		unsigned int swidth,
 					rwidth = 0,
@@ -1517,7 +1518,7 @@ print_aligned_vertical(const printTableContent *cont,
 			if (width < rwidth)
 				width = rwidth;
 
-			if (output_columns > 0)
+			if (cont->opt->format == PRINT_WRAPPED && output_columns > 0)
 			{
 				unsigned int min_width;
 
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index c8f3932edf0..dc44219631e 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -2854,6 +2854,32 @@ execute q;
 +------------------+-------------------+
 
 deallocate q;
+-- 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;
++-[ RECORD 1 ]-+
+| a | 10       |
+| b | 20       |
++-[ RECORD 2 ]-+
+| a | 30       |
+| b | 40       |
++---+----------+
+
+\pset format wrapped
+select * from psql_short_tab;
++-[ RECORD 1 ]-+
+| a | 10       |
+| b | 20       |
++-[ RECORD 2 ]-+
+| a | 30       |
+| b | 40       |
++---+----------+
+
+drop table psql_short_tab;
 \pset linestyle ascii
 \pset border 1
 -- support table for output-format tests (useful to create a footer)
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index dcdbd4fc020..b03a61f8656 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -499,6 +499,17 @@ execute q;
 
 deallocate q;
 
+-- 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;
+
 \pset linestyle ascii
 \pset border 1
 
-- 
2.54.0



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: bugfix - fix broken output in expanded aligned format, when data are too short
@ 2026-06-08 01:36  Michael Paquier <[email protected]>
  parent: Pavel Stehule <[email protected]>
  0 siblings, 1 reply; 10+ messages in thread

From: Michael Paquier @ 2026-06-08 01:36 UTC (permalink / raw)
  To: Pavel Stehule <[email protected]>; +Cc: getiancheng <[email protected]>; Chao Li <[email protected]>; PostgreSQL Hackers <[email protected]>

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


Attachments:

  [application/pgp-signature] signature.asc (833B, 2-signature.asc)
  download

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: bugfix - fix broken output in expanded aligned format, when data are too short
@ 2026-06-08 05:45  Michael Paquier <[email protected]>
  parent: Michael Paquier <[email protected]>
  0 siblings, 1 reply; 10+ messages in thread

From: Michael Paquier @ 2026-06-08 05:45 UTC (permalink / raw)
  To: Pavel Stehule <[email protected]>; +Cc: getiancheng <[email protected]>; Chao Li <[email protected]>; PostgreSQL Hackers <[email protected]>

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


Attachments:

  [application/pgp-signature] signature.asc (833B, 2-signature.asc)
  download

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: bugfix - fix broken output in expanded aligned format, when data are too short
@ 2026-06-08 06:39  Pavel Stehule <[email protected]>
  parent: Michael Paquier <[email protected]>
  0 siblings, 0 replies; 10+ messages in thread

From: Pavel Stehule @ 2026-06-08 06:39 UTC (permalink / raw)
  To: Michael Paquier <[email protected]>; +Cc: getiancheng <[email protected]>; Chao Li <[email protected]>; PostgreSQL Hackers <[email protected]>

Dne po 8. 6. 2026 7:45 uživatel Michael Paquier <[email protected]>
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
>


^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2026-06-08 06:39 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-03-23 19:42 bugfix - fix broken output in expanded aligned format, when data are too short Pavel Stehule <[email protected]>
2026-03-24 05:46 ` Pavel Stehule <[email protected]>
2026-03-24 06:12   ` Chao Li <[email protected]>
2026-03-24 06:31     ` Pavel Stehule <[email protected]>
2026-03-24 07:23       ` Pavel Stehule <[email protected]>
2026-05-26 06:22         ` Pavel Stehule <[email protected]>
2026-06-07 08:39           ` Pavel Stehule <[email protected]>
2026-06-08 01:36             ` Michael Paquier <[email protected]>
2026-06-08 05:45               ` Michael Paquier <[email protected]>
2026-06-08 06:39                 ` Pavel Stehule <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox