diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c index fe676a971b9..94ac6686253 100644 --- a/src/fe_utils/print.c +++ b/src/fe_utils/print.c @@ -1415,9 +1415,10 @@ print_aligned_vertical(const printTableContent *cont, } /* - * Calculate available width for data in wrapped mode + * Determine data column width: fit output width in wrapped mode, or + * ensure alignment with the record header line 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, @@ -1489,7 +1490,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 75488480542..f36f6d41571 100644 --- a/src/test/regress/expected/psql.out +++ b/src/test/regress/expected/psql.out @@ -2686,6 +2686,32 @@ execute q; +------------------+-------------------+ deallocate q; +-- expanded output with short-width columns +\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 1eef2a62de9..f2e5995bd17 100644 --- a/src/test/regress/sql/psql.sql +++ b/src/test/regress/sql/psql.sql @@ -428,6 +428,17 @@ execute q; deallocate q; +-- expanded output with short-width columns +\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