public inbox for [email protected]
help / color / mirror / Atom feedFrom: Pavel Stehule <[email protected]>
To: Chao Li <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: bugfix - fix broken output in expanded aligned format, when data are too short
Date: Tue, 24 Mar 2026 07:31:11 +0100
Message-ID: <CAFj8pRA_mSfE2bsvyHn-wyZMAQ1Oo35Hm5vXwhKHLF5dQ8pEAw@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAFj8pRCzGpsr9zTHbtTd4mGh2YPJqOEgLgt8JLiopuYA9_1xGw@mail.gmail.com>
<CAFj8pRAf1jYo8Nfz=sbfpMfaUBDsb77qGxdR+8JBxTH3_6MnBw@mail.gmail.com>
<[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
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: bugfix - fix broken output in expanded aligned format, when data are too short
In-Reply-To: <CAFj8pRA_mSfE2bsvyHn-wyZMAQ1Oo35Hm5vXwhKHLF5dQ8pEAw@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox