diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index 62850d8..8eae899 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -1160,7 +1160,9 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
 				dformatsize = 0;
 	struct lineptr *hlineptr,
 			   *dlineptr;
-	bool		is_pager = false;
+	bool		is_pager = false,
+				hmultiline = false,
+				dmultiline = false;
 	int			output_columns = 0;		/* Width of interactive console */
 
 	if (cancel_pressed)
@@ -1196,7 +1198,10 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
 		if (width > hwidth)
 			hwidth = width;
 		if (height > hheight)
+		{
 			hheight = height;
+			hmultiline = true;
+		}
 		if (fs > hformatsize)
 			hformatsize = fs;
 	}
@@ -1213,7 +1218,10 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
 		if (width > dwidth)
 			dwidth = width;
 		if (height > dheight)
+		{
 			dheight = height;
+			dmultiline = true;
+		}
 		if (fs > dformatsize)
 			dformatsize = fs;
 	}
@@ -1258,45 +1266,84 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
 	if (cont->opt->format == PRINT_WRAPPED)
 	{
 		/*
-		 * Calculate the available width to wrap the columns to after
-		 * subtracting the maximum header width and separators. At a minimum
-		 * enough to print "[ RECORD N ]"
+		 * Separators width
 		 */
 		unsigned int width,
-					swidth;
+					min_width,
+					swidth,
+					iwidth = 0;
 
 		if (opt_border == 0)
-			swidth = 1;			/* "header data" */
-		else if (opt_border == 1)
-			swidth = 3;			/* "header | data" */
-		else
-			swidth = 7;			/* "| header | data |" */
+		{
+			/*
+			 * For border = 0, one space in the middle.
+			 */
+			swidth = 1;
 
-		/* Wrap to maximum width */
-		width = dwidth + swidth + hwidth;
-		if ((output_columns > 0) && (width > output_columns))
+			if ((hmultiline) && 
+				(format == &pg_asciiformat_old))
+				iwidth++; /* for newline indicators */
+		}
+		else if (opt_border == 1)
 		{
-			dwidth = output_columns - hwidth - swidth;
-			width = output_columns;
+			/*
+			 * For border = 1, one space at the begging and at the end
+			 * of the lines. Оne for the pipe (|) in the middle
+			 * between the two spaces.
+			 */
+			swidth = 5;
 		}
+		else
+			/*
+			 * For border = 2, two more for the pipes (|) at the begging and
+			 * at the end of the lines.
+			 */
+			swidth = 7;
 
-		/* Wrap to minimum width */
+		min_width = hwidth + iwidth + swidth + 3;
+
+		/* 
+		 * Record header width
+		 */
 		if (!opt_tuples_only)
 		{
-			int			delta = 1 + log10(cont->nrows) - width;
-
+			/* 
+			 * Record number
+			 */
+			unsigned int rwidth = 1 + log10(cont->nrows);
 			if (opt_border == 0)
-				delta += 6;		/* "* RECORD " */
+				rwidth += 9;	/* "* RECORD " */
 			else if (opt_border == 1)
-				delta += 10;	/* "-[ RECORD  ]" */
+				rwidth += 12;	/* "-[ RECORD  ]" */
 			else
-				delta += 15;	/* "+-[ RECORD  ]-+" */
+				rwidth += 15;	/* "+-[ RECORD  ]-+" */
+
+			if (rwidth > min_width)
+				min_width = rwidth;
+		}
+
+		/* Wrap to minimum width */
+		width = hwidth + iwidth + swidth + dwidth;
+		if ((width < min_width) || (output_columns < min_width))
+			width = min_width - hwidth - iwidth - swidth;
+		else if (output_columns > 0)
+			/*
+			 * Wrap to maximum width
+			 */
+			width = output_columns - hwidth - iwidth - swidth;
 
-			if (delta > 0)
-				dwidth += delta;
+		if ((width < dwidth) || (dheight > 1))
+		{
+			dmultiline = true;
+			if ((opt_border == 0) && 
+				(format != &pg_asciiformat_old))
+			{
+				width--; /* for wrap indicators */
+				if (hmultiline)
+					width--;
+			}
 		}
-		else if (dwidth < 3)
-			dwidth = 3;
+		dwidth = width;
 	}
 
 	/* print records */
@@ -1321,11 +1368,18 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
 		/* Print record header (e.g. "[ RECORD N ]") above each record */
 		if (i % cont->ncolumns == 0)
 		{
+			unsigned int lhwidth = hwidth,
+						 ldwidth = dwidth;
+			if (opt_border == 1)
+			{
+				lhwidth++;
+				ldwidth++;
+			}
 			if (!opt_tuples_only)
-				print_aligned_vertical_line(cont, record++, hwidth, dwidth,
-											pos, fout);
+				print_aligned_vertical_line(cont, record++, lhwidth,
+											ldwidth, pos, fout);
 			else if (i != 0 || !cont->opt->start_table || opt_border == 2)
-				print_aligned_vertical_line(cont, 0, hwidth, dwidth,
+				print_aligned_vertical_line(cont, 0, lhwidth, ldwidth,
 											pos, fout);
 		}
 
@@ -1354,35 +1408,56 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
 			/* Header (never wrapped so just need to deal with newlines) */
 			if (!hcomplete)
 			{
-				int			swidth,
-							twidth = hwidth + 1;
-
-				fputs(hline ? format->header_nl_left : " ", fout);
-				strlen_max_width(hlineptr[hline].ptr, &twidth,
+				int			swidth = hwidth,
+							target_width = hwidth;
+				/*
+				 * Left spacer or new line indicator
+				 */
+				if ((opt_border > 0) ||
+					(hmultiline && (format == &pg_asciiformat_old)))
+					fputs(hline ? format->header_nl_left : " ", fout);
+				/*
+				 * Header text
+				 */
+				strlen_max_width(hlineptr[hline].ptr, &target_width,
 								 encoding);
 				fprintf(fout, "%-s", hlineptr[hline].ptr);
 
-				swidth = hwidth - twidth;
-				if (swidth > 0) /* spacer */
+				/*
+				 * Spacer
+				 */
+				swidth -= target_width;
+				if (swidth > 0)
 					fprintf(fout, "%*s", swidth, " ");
 
+				/* 
+				 * New line indicator or separator's space
+				 */
 				if (hlineptr[hline + 1].ptr)
 				{
 					/* More lines after this one due to a newline */
-					fputs(format->header_nl_right, fout);
+					if ((opt_border > 0) ||
+						(hmultiline && (format != &pg_asciiformat_old)))
+						fputs(format->header_nl_right, fout);
 					hline++;
 				}
 				else
 				{
 					/* This was the last line of the header */
-					fputs(" ", fout);
+					if ((opt_border > 0) ||
+						(hmultiline && (format != &pg_asciiformat_old)))
+						fputs(" ", fout);
 					hcomplete = 1;
 				}
 			}
 			else
 			{
-				/* Header exhausted but more data for column */
-				fprintf(fout, "%*s", hwidth + 2, "");
+				unsigned int swidth = hwidth;
+				if (opt_border > 0)
+					swidth += 2;
+				else if (hmultiline)
+					swidth++;
+				fprintf(fout, "%*s", swidth, " ");
 			}
 
 			/* Separator */
@@ -1401,13 +1476,18 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
 			/* Data */
 			if (!dcomplete)
 			{
-				int			target_width,
+				int			target_width = dwidth,
 							bytes_to_output,
-							swidth;
+							swidth = dwidth;
 
+				/*
+				 * Left spacer on wrap indicator
+				 */
 				fputs(!dcomplete && !offset ? " " : format->wrap_left, fout);
 
-				target_width = dwidth;
+				/*
+				 * Data text
+				 */
 				bytes_to_output = strlen_max_width(dlineptr[dline].ptr + offset,
 												   &target_width, encoding);
 				fputnbytes(fout, (char *) (dlineptr[dline].ptr + offset),
@@ -1416,20 +1496,24 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
 				chars_to_output -= target_width;
 				offset += bytes_to_output;
 
-				/* spacer */
-				swidth = dwidth - target_width;
+				/* Spacer */
+				swidth -= target_width;
 				if (swidth > 0)
-					fprintf(fout, "%*s", swidth, "");
+					fprintf(fout, "%*s", swidth, " ");
 
 				if (chars_to_output)
 				{
 					/* continuing a wrapped column */
-					fputs(format->wrap_right, fout);
+					if ((opt_border > 0) ||
+						(dmultiline && (format != &pg_asciiformat_old)))
+						fputs(format->wrap_right, fout);
 				}
 				else if (dlineptr[dline + 1].ptr)
 				{
 					/* reached a newline in the column */
-					fputs(format->nl_right, fout);
+					if ((opt_border > 0) ||
+						(dmultiline && (format != &pg_asciiformat_old)))
+						fputs(format->nl_right, fout);
 					dline++;
 					offset = 0;
 					chars_to_output = dlineptr[dline].width;
@@ -1437,10 +1521,13 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
 				else
 				{
 					/* reached the end of the cell */
-					fputs(" ", fout);
+					if ((opt_border > 0) ||
+						(dmultiline && (format != &pg_asciiformat_old)))
+						fputs(" ", fout);
 					dcomplete = 1;
 				}
 
+				/* Right border */
 				if (opt_border == 2)
 					fputs(dformat->rightvrule, fout);
 
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index c7dbd54..59e9e9b 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -69,20 +69,20 @@ Table attributes (tableattr) unset.
 Title (title) unset.
 Tuples only (tuples_only) is off.
 -- test multi-line headers, wrapping, and newline indicators
-prepare q as select array_to_string(array_agg(repeat('x',2*n)),E'\n') as "a
+prepare q as select array_to_string(array_agg(repeat('x',2*n)),E'\n') as "ab
 
-b", array_to_string(array_agg(repeat('y',20-2*n)),E'\n') as "a
-b" from generate_series(1,10) as n(n) group by n>1 ;
+c", array_to_string(array_agg(repeat('y',20-2*n)),E'\n') as "a
+bc" from generate_series(1,10) as n(n) group by n>1 ;
 \pset linestyle ascii
 \pset expanded off
 \pset columns 40
 \pset border 0
 \pset format unaligned
 execute q;
-a
+ab
 
-b|a
-b
+c|a
+bc
 xx|yyyyyyyyyyyyyyyyyy
 xxxx
 xxxxxx
@@ -104,9 +104,9 @@ yy
 (2 rows)
 \pset format aligned
 execute q;
-         a          +        a         +
-                    +        b          
-         b                              
+         ab         +        a         +
+                    +        bc         
+         c                              
 -------------------- ------------------
 xx                   yyyyyyyyyyyyyyyyyy
 xxxx                +yyyyyyyyyyyyyyyy  +
@@ -122,9 +122,9 @@ xxxxxxxxxxxxxxxxxxxx
 
 \pset format wrapped
 execute q;
-         a          +        a         +
-                    +        b          
-         b                              
+         ab         +        a         +
+                    +        bc         
+         c                              
 -------------------- ------------------
 xx                   yyyyyyyyyyyyyyyyyy
 xxxx                +yyyyyyyyyyyyyyyy  +
@@ -141,10 +141,10 @@ xxxxxxxxxxxxxxxxxxxx
 \pset border 1
 \pset format unaligned
 execute q;
-a
+ab
 
-b|a
-b
+c|a
+bc
 xx|yyyyyyyyyyyyyyyyyy
 xxxx
 xxxxxx
@@ -166,9 +166,9 @@ yy
 (2 rows)
 \pset format aligned
 execute q;
-          a          +|         a         +
-                     +|         b          
-          b           |                    
+          ab         +|         a         +
+                     +|         bc         
+          c           |                    
 ----------------------+--------------------
  xx                   | yyyyyyyyyyyyyyyyyy
  xxxx                +| yyyyyyyyyyyyyyyy  +
@@ -184,9 +184,9 @@ execute q;
 
 \pset format wrapped
 execute q;
-         a        +|         a         +
-                  +|         b          
-         b         |                    
+        ab        +|         a         +
+                  +|         bc         
+         c         |                    
 -------------------+--------------------
  xx                | yyyyyyyyyyyyyyyyyy
  xxxx             +| yyyyyyyyyyyyyyyy  +
@@ -205,10 +205,10 @@ execute q;
 \pset border 2
 \pset format unaligned
 execute q;
-a
+ab
 
-b|a
-b
+c|a
+bc
 xx|yyyyyyyyyyyyyyyyyy
 xxxx
 xxxxxx
@@ -231,9 +231,9 @@ yy
 \pset format aligned
 execute q;
 +----------------------+--------------------+
-|          a          +|         a         +|
-|                     +|         b          |
-|          b           |                    |
+|          ab         +|         a         +|
+|                     +|         bc         |
+|          c           |                    |
 +----------------------+--------------------+
 | xx                   | yyyyyyyyyyyyyyyyyy |
 | xxxx                +| yyyyyyyyyyyyyyyy  +|
@@ -251,9 +251,9 @@ execute q;
 \pset format wrapped
 execute q;
 +-----------------+--------------------+
-|        a       +|         a         +|
-|                +|         b          |
-|        b        |                    |
+|       ab       +|         a         +|
+|                +|         bc         |
+|        c        |                    |
 +-----------------+--------------------+
 | xx              | yyyyyyyyyyyyyyyyyy |
 | xxxx           +| yyyyyyyyyyyyyyyy  +|
@@ -276,15 +276,15 @@ execute q;
 \pset border 0
 \pset format unaligned
 execute q;
-a
+ab
 
-b|xx
+c|xx
 a
-b|yyyyyyyyyyyyyyyyyy
+bc|yyyyyyyyyyyyyyyyyy
 
-a
+ab
 
-b|xxxx
+c|xxxx
 xxxxxx
 xxxxxxxx
 xxxxxxxxxx
@@ -294,7 +294,7 @@ xxxxxxxxxxxxxxxx
 xxxxxxxxxxxxxxxxxx
 xxxxxxxxxxxxxxxxxxxx
 a
-b|yyyyyyyyyyyyyyyy
+bc|yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyy
 yyyyyyyyyyyy
 yyyyyyyyyy
@@ -305,24 +305,24 @@ yy
 
 \pset format aligned
 execute q;
-* Record 1           
- a+ xx                   
+* Record 1            
+ab+ xx                   
   +
- b 
- a+ yyyyyyyyyyyyyyyyyy   
- b 
-* Record 2           
- a+ xxxx                +
+c  
+a + yyyyyyyyyyyyyyyyyy   
+bc 
+* Record 2            
+ab+ xxxx                +
   + xxxxxx              +
- b  xxxxxxxx            +
+c   xxxxxxxx            +
     xxxxxxxxxx          +
     xxxxxxxxxxxx        +
     xxxxxxxxxxxxxx      +
     xxxxxxxxxxxxxxxx    +
     xxxxxxxxxxxxxxxxxx  +
     xxxxxxxxxxxxxxxxxxxx 
- a+ yyyyyyyyyyyyyyyy    +
- b  yyyyyyyyyyyyyy      +
+a + yyyyyyyyyyyyyyyy    +
+bc  yyyyyyyyyyyyyy      +
     yyyyyyyyyyyy        +
     yyyyyyyyyy          +
     yyyyyyyy            +
@@ -333,45 +333,48 @@ execute q;
 
 \pset format wrapped
 execute q;
-* Record 1         
- a+ xx                 
+* Record 1       
+ab+ xx              
   +
- b 
- a+ yyyyyyyyyyyyyyyyyy 
- b 
-* Record 2         
- a+ xxxx              +
-  + xxxxxx            +
- b  xxxxxxxx          +
-    xxxxxxxxxx        +
-    xxxxxxxxxxxx      +
-    xxxxxxxxxxxxxx    +
-    xxxxxxxxxxxxxxxx  +
-    xxxxxxxxxxxxxxxxxx+
-    xxxxxxxxxxxxxxxxxx.
-   .xx                 
- a+ yyyyyyyyyyyyyyyy  +
- b  yyyyyyyyyyyyyy    +
-    yyyyyyyyyyyy      +
-    yyyyyyyyyy        +
-    yyyyyyyy          +
-    yyyyyy            +
-    yyyy              +
-    yy                +
-                       
+c  
+a + yyyyyyyyyyyyyyy.
+bc .yyy             
+* Record 2       
+ab+ xxxx           +
+  + xxxxxx         +
+c   xxxxxxxx       +
+    xxxxxxxxxx     +
+    xxxxxxxxxxxx   +
+    xxxxxxxxxxxxxx +
+    xxxxxxxxxxxxxxx.
+   .x              +
+    xxxxxxxxxxxxxxx.
+   .xxx            +
+    xxxxxxxxxxxxxxx.
+   .xxxxx           
+a + yyyyyyyyyyyyyyy.
+bc .y              +
+    yyyyyyyyyyyyyy +
+    yyyyyyyyyyyy   +
+    yyyyyyyyyy     +
+    yyyyyyyy       +
+    yyyyyy         +
+    yyyy           +
+    yy             +
+                    
 
 \pset border 1
 \pset format unaligned
 execute q;
-a
+ab
 
-b|xx
+c|xx
 a
-b|yyyyyyyyyyyyyyyyyy
+bc|yyyyyyyyyyyyyyyyyy
 
-a
+ab
 
-b|xxxx
+c|xxxx
 xxxxxx
 xxxxxxxx
 xxxxxxxxxx
@@ -381,7 +384,7 @@ xxxxxxxxxxxxxxxx
 xxxxxxxxxxxxxxxxxx
 xxxxxxxxxxxxxxxxxxxx
 a
-b|yyyyyyyyyyyyyyyy
+bc|yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyy
 yyyyyyyyyyyy
 yyyyyyyyyy
@@ -392,74 +395,78 @@ yy
 
 \pset format aligned
 execute q;
--[ RECORD 1 ]-----------
- a+| xx                   
-  +|
- b |
- a+| yyyyyyyyyyyyyyyyyy   
- b |
--[ RECORD 2 ]-----------
- a+| xxxx                +
-  +| xxxxxx              +
- b | xxxxxxxx            +
-   | xxxxxxxxxx          +
-   | xxxxxxxxxxxx        +
-   | xxxxxxxxxxxxxx      +
-   | xxxxxxxxxxxxxxxx    +
-   | xxxxxxxxxxxxxxxxxx  +
-   | xxxxxxxxxxxxxxxxxxxx 
- a+| yyyyyyyyyyyyyyyy    +
- b | yyyyyyyyyyyyyy      +
-   | yyyyyyyyyyyy        +
-   | yyyyyyyyyy          +
-   | yyyyyyyy            +
-   | yyyyyy              +
-   | yyyy                +
-   | yy                  +
-   |                      
+-[ RECORD 1 ]--------------
+ ab+| xx                   
+   +|
+ c  |
+ a +| yyyyyyyyyyyyyyyyyy   
+ bc |
+-[ RECORD 2 ]--------------
+ ab+| xxxx                +
+   +| xxxxxx              +
+ c  | xxxxxxxx            +
+    | xxxxxxxxxx          +
+    | xxxxxxxxxxxx        +
+    | xxxxxxxxxxxxxx      +
+    | xxxxxxxxxxxxxxxx    +
+    | xxxxxxxxxxxxxxxxxx  +
+    | xxxxxxxxxxxxxxxxxxxx 
+ a +| yyyyyyyyyyyyyyyy    +
+ bc | yyyyyyyyyyyyyy      +
+    | yyyyyyyyyyyy        +
+    | yyyyyyyyyy          +
+    | yyyyyyyy            +
+    | yyyyyy              +
+    | yyyy                +
+    | yy                  +
+    |                      
 
 \pset format wrapped
 execute q;
 -[ RECORD 1 ]-------
- a+| xx               
-  +|
- b |
- a+| yyyyyyyyyyyyyyyy.
- b |.yy               
+ ab+| xx            
+   +|
+ c  |
+ a +| yyyyyyyyyyyyy.
+ bc |.yyyyy         
 -[ RECORD 2 ]-------
- a+| xxxx            +
-  +| xxxxxx          +
- b | xxxxxxxx        +
-   | xxxxxxxxxx      +
-   | xxxxxxxxxxxx    +
-   | xxxxxxxxxxxxxx  +
-   | xxxxxxxxxxxxxxxx+
-   | xxxxxxxxxxxxxxxx.
-   |.xx              +
-   | xxxxxxxxxxxxxxxx.
-   |.xxxx             
- a+| yyyyyyyyyyyyyyyy+
- b | yyyyyyyyyyyyyy  +
-   | yyyyyyyyyyyy    +
-   | yyyyyyyyyy      +
-   | yyyyyyyy        +
-   | yyyyyy          +
-   | yyyy            +
-   | yy              +
-   |                  
+ ab+| xxxx         +
+   +| xxxxxx       +
+ c  | xxxxxxxx     +
+    | xxxxxxxxxx   +
+    | xxxxxxxxxxxx +
+    | xxxxxxxxxxxxx.
+    |.x            +
+    | xxxxxxxxxxxxx.
+    |.xxx          +
+    | xxxxxxxxxxxxx.
+    |.xxxxx        +
+    | xxxxxxxxxxxxx.
+    |.xxxxxxx       
+ a +| yyyyyyyyyyyyy.
+ bc |.yyy          +
+    | yyyyyyyyyyyyy.
+    |.y            +
+    | yyyyyyyyyyyy +
+    | yyyyyyyyyy   +
+    | yyyyyyyy     +
+    | yyyyyy       +
+    | yyyy         +
+    | yy           +
+    |               
 
 \pset border 2
 \pset format unaligned
 execute q;
-a
+ab
 
-b|xx
+c|xx
 a
-b|yyyyyyyyyyyyyyyyyy
+bc|yyyyyyyyyyyyyyyyyy
 
-a
+ab
 
-b|xxxx
+c|xxxx
 xxxxxx
 xxxxxxxx
 xxxxxxxxxx
@@ -469,7 +476,7 @@ xxxxxxxxxxxxxxxx
 xxxxxxxxxxxxxxxxxx
 xxxxxxxxxxxxxxxxxxxx
 a
-b|yyyyyyyyyyyyyyyy
+bc|yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyy
 yyyyyyyyyyyy
 yyyyyyyyyy
@@ -480,67 +487,69 @@ yy
 
 \pset format aligned
 execute q;
-+-[ RECORD 1 ]-------------+
-| a+| xx                   |
-|  +|                      |
-| b |                      |
-| a+| yyyyyyyyyyyyyyyyyy   |
-| b |                      |
-+-[ RECORD 2 ]-------------+
-| a+| xxxx                +|
-|  +| xxxxxx              +|
-| b | xxxxxxxx            +|
-|   | xxxxxxxxxx          +|
-|   | xxxxxxxxxxxx        +|
-|   | xxxxxxxxxxxxxx      +|
-|   | xxxxxxxxxxxxxxxx    +|
-|   | xxxxxxxxxxxxxxxxxx  +|
-|   | xxxxxxxxxxxxxxxxxxxx |
-| a+| yyyyyyyyyyyyyyyy    +|
-| b | yyyyyyyyyyyyyy      +|
-|   | yyyyyyyyyyyy        +|
-|   | yyyyyyyyyy          +|
-|   | yyyyyyyy            +|
-|   | yyyyyy              +|
-|   | yyyy                +|
-|   | yy                  +|
-|   |                      |
-+---+----------------------+
++-[ RECORD 1 ]--------------+
+| ab+| xx                   |
+|   +|                      |
+| c  |                      |
+| a +| yyyyyyyyyyyyyyyyyy   |
+| bc |                      |
++-[ RECORD 2 ]--------------+
+| ab+| xxxx                +|
+|   +| xxxxxx              +|
+| c  | xxxxxxxx            +|
+|    | xxxxxxxxxx          +|
+|    | xxxxxxxxxxxx        +|
+|    | xxxxxxxxxxxxxx      +|
+|    | xxxxxxxxxxxxxxxx    +|
+|    | xxxxxxxxxxxxxxxxxx  +|
+|    | xxxxxxxxxxxxxxxxxxxx |
+| a +| yyyyyyyyyyyyyyyy    +|
+| bc | yyyyyyyyyyyyyy      +|
+|    | yyyyyyyyyyyy        +|
+|    | yyyyyyyyyy          +|
+|    | yyyyyyyy            +|
+|    | yyyyyy              +|
+|    | yyyy                +|
+|    | yy                  +|
+|    |                      |
++----+----------------------+
 
 \pset format wrapped
 execute q;
 +-[ RECORD 1 ]-----+
-| a+| xx           |
-|  +|              |
-| b |              |
-| a+| yyyyyyyyyyyy.|
-| b |.yyyyyy       |
+| ab+| xx          |
+|   +|             |
+| c  |             |
+| a +| yyyyyyyyyyy.|
+| bc |.yyyyyyy     |
 +-[ RECORD 2 ]-----+
-| a+| xxxx        +|
-|  +| xxxxxx      +|
-| b | xxxxxxxx    +|
-|   | xxxxxxxxxx  +|
-|   | xxxxxxxxxxxx+|
-|   | xxxxxxxxxxxx.|
-|   |.xx          +|
-|   | xxxxxxxxxxxx.|
-|   |.xxxx        +|
-|   | xxxxxxxxxxxx.|
-|   |.xxxxxx      +|
-|   | xxxxxxxxxxxx.|
-|   |.xxxxxxxx     |
-| a+| yyyyyyyyyyyy.|
-| b |.yyyy        +|
-|   | yyyyyyyyyyyy.|
-|   |.yy          +|
-|   | yyyyyyyyyyyy+|
-|   | yyyyyyyyyy  +|
-|   | yyyyyyyy    +|
-|   | yyyyyy      +|
-|   | yyyy        +|
-|   | yy          +|
-|   |              |
-+---+--------------+
+| ab+| xxxx       +|
+|   +| xxxxxx     +|
+| c  | xxxxxxxx   +|
+|    | xxxxxxxxxx +|
+|    | xxxxxxxxxxx.|
+|    |.x          +|
+|    | xxxxxxxxxxx.|
+|    |.xxx        +|
+|    | xxxxxxxxxxx.|
+|    |.xxxxx      +|
+|    | xxxxxxxxxxx.|
+|    |.xxxxxxx    +|
+|    | xxxxxxxxxxx.|
+|    |.xxxxxxxxx   |
+| a +| yyyyyyyyyyy.|
+| bc |.yyyyy      +|
+|    | yyyyyyyyyyy.|
+|    |.yyy        +|
+|    | yyyyyyyyyyy.|
+|    |.y          +|
+|    | yyyyyyyyyy +|
+|    | yyyyyyyy   +|
+|    | yyyyyy     +|
+|    | yyyy       +|
+|    | yy         +|
+|    |             |
++----+-------------+
 
 \pset linestyle old-ascii
 \pset expanded off
@@ -548,10 +557,10 @@ execute q;
 \pset border 0
 \pset format unaligned
 execute q;
-a
+ab
 
-b|a
-b
+c|a
+bc
 xx|yyyyyyyyyyyyyyyyyy
 xxxx
 xxxxxx
@@ -573,9 +582,9 @@ yy
 (2 rows)
 \pset format aligned
 execute q;
-         a                   a         
-                    +        b         
-         b          +                  
+         ab                  a         
+                    +        bc        
+         c          +                  
 -------------------- ------------------
 xx                   yyyyyyyyyyyyyyyyyy
 xxxx                 yyyyyyyyyyyyyyyy   
@@ -591,9 +600,9 @@ xxxxxxxxxxxxxxxxxxxx
 
 \pset format wrapped
 execute q;
-         a                   a         
-                    +        b         
-         b          +                  
+         ab                  a         
+                    +        bc        
+         c          +                  
 -------------------- ------------------
 xx                   yyyyyyyyyyyyyyyyyy
 xxxx                 yyyyyyyyyyyyyyyy   
@@ -610,10 +619,10 @@ xxxxxxxxxxxxxxxxxxxx
 \pset border 1
 \pset format unaligned
 execute q;
-a
+ab
 
-b|a
-b
+c|a
+bc
 xx|yyyyyyyyyyyyyyyyyy
 xxxx
 xxxxxx
@@ -635,9 +644,9 @@ yy
 (2 rows)
 \pset format aligned
 execute q;
-          a           |         a          
-+                     |+        b          
-+         b           |+                   
+          ab          |         a          
++                     |+        bc         
++         c           |+                   
 ----------------------+--------------------
  xx                   | yyyyyyyyyyyyyyyyyy
  xxxx                 | yyyyyyyyyyyyyyyy   
@@ -653,9 +662,9 @@ execute q;
 
 \pset format wrapped
 execute q;
-         a         |         a          
-+                  |+        b          
-+        b         |+                   
+        ab         |         a          
++                  |+        bc         
++        c         |+                   
 -------------------+--------------------
  xx                | yyyyyyyyyyyyyyyyyy
  xxxx              | yyyyyyyyyyyyyyyy   
@@ -674,10 +683,10 @@ execute q;
 \pset border 2
 \pset format unaligned
 execute q;
-a
+ab
 
-b|a
-b
+c|a
+bc
 xx|yyyyyyyyyyyyyyyyyy
 xxxx
 xxxxxx
@@ -700,9 +709,9 @@ yy
 \pset format aligned
 execute q;
 +----------------------+--------------------+
-|          a           |         a          |
-|+                     |+        b          |
-|+         b           |+                   |
+|          ab          |         a          |
+|+                     |+        bc         |
+|+         c           |+                   |
 +----------------------+--------------------+
 | xx                   | yyyyyyyyyyyyyyyyyy |
 | xxxx                 | yyyyyyyyyyyyyyyy   |
@@ -720,9 +729,9 @@ execute q;
 \pset format wrapped
 execute q;
 +-----------------+--------------------+
-|        a        |         a          |
-|+                |+        b          |
-|+       b        |+                   |
+|       ab        |         a          |
+|+                |+        bc         |
+|+       c        |+                   |
 +-----------------+--------------------+
 | xx              | yyyyyyyyyyyyyyyyyy |
 | xxxx            | yyyyyyyyyyyyyyyy   |
@@ -745,15 +754,15 @@ execute q;
 \pset border 0
 \pset format unaligned
 execute q;
-a
+ab
 
-b|xx
+c|xx
 a
-b|yyyyyyyyyyyyyyyyyy
+bc|yyyyyyyyyyyyyyyyyy
 
-a
+ab
 
-b|xxxx
+c|xxxx
 xxxxxx
 xxxxxxxx
 xxxxxxxxxx
@@ -763,7 +772,7 @@ xxxxxxxxxxxxxxxx
 xxxxxxxxxxxxxxxxxx
 xxxxxxxxxxxxxxxxxxxx
 a
-b|yyyyyyyyyyyyyyyy
+bc|yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyy
 yyyyyyyyyyyy
 yyyyyyyyyy
@@ -774,73 +783,74 @@ yy
 
 \pset format aligned
 execute q;
-* Record 1           
- a  xx                   
+* Record 1            
+ ab xx                  
 +  
-+b 
- a  yyyyyyyyyyyyyyyyyy   
-+b 
-* Record 2           
- a  xxxx                 
-+   xxxxxx               
-+b  xxxxxxxx             
-    xxxxxxxxxx           
-    xxxxxxxxxxxx         
-    xxxxxxxxxxxxxx       
-    xxxxxxxxxxxxxxxx     
-    xxxxxxxxxxxxxxxxxx   
-    xxxxxxxxxxxxxxxxxxxx 
- a  yyyyyyyyyyyyyyyy     
-+b  yyyyyyyyyyyyyy       
-    yyyyyyyyyyyy         
-    yyyyyyyyyy           
-    yyyyyyyy             
-    yyyyyy               
-    yyyy                 
-    yy                   
-                         
++c 
+ a  yyyyyyyyyyyyyyyyyy  
++bc
+* Record 2            
+ ab xxxx                
++   xxxxxx              
++c  xxxxxxxx            
+    xxxxxxxxxx          
+    xxxxxxxxxxxx        
+    xxxxxxxxxxxxxx      
+    xxxxxxxxxxxxxxxx    
+    xxxxxxxxxxxxxxxxxx  
+    xxxxxxxxxxxxxxxxxxxx
+ a  yyyyyyyyyyyyyyyy    
++bc yyyyyyyyyyyyyy      
+    yyyyyyyyyyyy        
+    yyyyyyyyyy          
+    yyyyyyyy            
+    yyyyyy              
+    yyyy                
+    yy                  
+                        
 
 \pset format wrapped
 execute q;
-* Record 1         
- a  xx                 
+* Record 1        
+ ab xx              
 +  
-+b 
- a  yyyyyyyyyyyyyyyyyy 
-+b 
-* Record 2         
- a  xxxx               
-+   xxxxxx             
-+b  xxxxxxxx           
-    xxxxxxxxxx         
-    xxxxxxxxxxxx       
-    xxxxxxxxxxxxxx     
-    xxxxxxxxxxxxxxxx   
-    xxxxxxxxxxxxxxxxxx 
-    xxxxxxxxxxxxxxxxxx 
-    xx                 
- a  yyyyyyyyyyyyyyyy   
-+b  yyyyyyyyyyyyyy     
-    yyyyyyyyyyyy       
-    yyyyyyyyyy         
-    yyyyyyyy           
-    yyyyyy             
-    yyyy               
-    yy                 
-                       
++c 
+ a  yyyyyyyyyyyyyyyy
++bc yy              
+* Record 2        
+ ab xxxx            
++   xxxxxx          
++c  xxxxxxxx        
+    xxxxxxxxxx      
+    xxxxxxxxxxxx    
+    xxxxxxxxxxxxxx  
+    xxxxxxxxxxxxxxxx
+    xxxxxxxxxxxxxxxx
+    xx              
+    xxxxxxxxxxxxxxxx
+    xxxx            
+ a  yyyyyyyyyyyyyyyy
++bc yyyyyyyyyyyyyy  
+    yyyyyyyyyyyy    
+    yyyyyyyyyy      
+    yyyyyyyy        
+    yyyyyy          
+    yyyy            
+    yy              
+                    
 
 \pset border 1
 \pset format unaligned
 execute q;
-a
+ab
 
-b|xx
+c|xx
 a
-b|yyyyyyyyyyyyyyyyyy
+bc|yyyyyyyyyyyyyyyyyy
 
-a
+ab
 
-b|xxxx
+c|xxxx
 xxxxxx
 xxxxxxxx
 xxxxxxxxxx
@@ -850,7 +860,7 @@ xxxxxxxxxxxxxxxx
 xxxxxxxxxxxxxxxxxx
 xxxxxxxxxxxxxxxxxxxx
 a
-b|yyyyyyyyyyyyyyyy
+bc|yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyy
 yyyyyyyyyyyy
 yyyyyyyyyy
@@ -861,74 +871,78 @@ yy
 
 \pset format aligned
 execute q;
--[ RECORD 1 ]-----------
- a | xx                   
-+  ;
-+b ;
- a | yyyyyyyyyyyyyyyyyy   
-+b ;
--[ RECORD 2 ]-----------
- a | xxxx                 
-+  : xxxxxx               
-+b : xxxxxxxx             
-   : xxxxxxxxxx           
-   : xxxxxxxxxxxx         
-   : xxxxxxxxxxxxxx       
-   : xxxxxxxxxxxxxxxx     
-   : xxxxxxxxxxxxxxxxxx   
-   : xxxxxxxxxxxxxxxxxxxx 
- a | yyyyyyyyyyyyyyyy     
-+b : yyyyyyyyyyyyyy       
-   : yyyyyyyyyyyy         
-   : yyyyyyyyyy           
-   : yyyyyyyy             
-   : yyyyyy               
-   : yyyy                 
-   : yy                   
-   :                      
+-[ RECORD 1 ]--------------
+ ab | xx                   
++   ;
++c  ;
+ a  | yyyyyyyyyyyyyyyyyy   
++bc ;
+-[ RECORD 2 ]--------------
+ ab | xxxx                 
++   : xxxxxx               
++c  : xxxxxxxx             
+    : xxxxxxxxxx           
+    : xxxxxxxxxxxx         
+    : xxxxxxxxxxxxxx       
+    : xxxxxxxxxxxxxxxx     
+    : xxxxxxxxxxxxxxxxxx   
+    : xxxxxxxxxxxxxxxxxxxx 
+ a  | yyyyyyyyyyyyyyyy     
++bc : yyyyyyyyyyyyyy       
+    : yyyyyyyyyyyy         
+    : yyyyyyyyyy           
+    : yyyyyyyy             
+    : yyyyyy               
+    : yyyy                 
+    : yy                   
+    :                      
 
 \pset format wrapped
 execute q;
 -[ RECORD 1 ]-------
- a | xx               
-+  ;
-+b ;
- a | yyyyyyyyyyyyyyyy 
-+b ; yy               
+ ab | xx            
++   ;
++c  ;
+ a  | yyyyyyyyyyyyy 
++bc ; yyyyy         
 -[ RECORD 2 ]-------
- a | xxxx             
-+  : xxxxxx           
-+b : xxxxxxxx         
-   : xxxxxxxxxx       
-   : xxxxxxxxxxxx     
-   : xxxxxxxxxxxxxx   
-   : xxxxxxxxxxxxxxxx 
-   : xxxxxxxxxxxxxxxx 
-   ; xx               
-   : xxxxxxxxxxxxxxxx 
-   ; xxxx             
- a | yyyyyyyyyyyyyyyy 
-+b : yyyyyyyyyyyyyy   
-   : yyyyyyyyyyyy     
-   : yyyyyyyyyy       
-   : yyyyyyyy         
-   : yyyyyy           
-   : yyyy             
-   : yy               
-   :                  
+ ab | xxxx          
++   : xxxxxx        
++c  : xxxxxxxx      
+    : xxxxxxxxxx    
+    : xxxxxxxxxxxx  
+    : xxxxxxxxxxxxx 
+    ; x             
+    : xxxxxxxxxxxxx 
+    ; xxx           
+    : xxxxxxxxxxxxx 
+    ; xxxxx         
+    : xxxxxxxxxxxxx 
+    ; xxxxxxx       
+ a  | yyyyyyyyyyyyy 
++bc ; yyy           
+    : yyyyyyyyyyyyy 
+    ; y             
+    : yyyyyyyyyyyy  
+    : yyyyyyyyyy    
+    : yyyyyyyy      
+    : yyyyyy        
+    : yyyy          
+    : yy            
+    :               
 
 \pset border 2
 \pset format unaligned
 execute q;
-a
+ab
 
-b|xx
+c|xx
 a
-b|yyyyyyyyyyyyyyyyyy
+bc|yyyyyyyyyyyyyyyyyy
 
-a
+ab
 
-b|xxxx
+c|xxxx
 xxxxxx
 xxxxxxxx
 xxxxxxxxxx
@@ -938,7 +952,7 @@ xxxxxxxxxxxxxxxx
 xxxxxxxxxxxxxxxxxx
 xxxxxxxxxxxxxxxxxxxx
 a
-b|yyyyyyyyyyyyyyyy
+bc|yyyyyyyyyyyyyyyy
 yyyyyyyyyyyyyy
 yyyyyyyyyyyy
 yyyyyyyyyy
@@ -949,66 +963,1031 @@ yy
 
 \pset format aligned
 execute q;
-+-[ RECORD 1 ]-------------+
-| a | xx                   |
-|+  ;                      |
-|+b ;                      |
-| a | yyyyyyyyyyyyyyyyyy   |
-|+b ;                      |
-+-[ RECORD 2 ]-------------+
-| a | xxxx                 |
-|+  : xxxxxx               |
-|+b : xxxxxxxx             |
-|   : xxxxxxxxxx           |
-|   : xxxxxxxxxxxx         |
-|   : xxxxxxxxxxxxxx       |
-|   : xxxxxxxxxxxxxxxx     |
-|   : xxxxxxxxxxxxxxxxxx   |
-|   : xxxxxxxxxxxxxxxxxxxx |
-| a | yyyyyyyyyyyyyyyy     |
-|+b : yyyyyyyyyyyyyy       |
-|   : yyyyyyyyyyyy         |
-|   : yyyyyyyyyy           |
-|   : yyyyyyyy             |
-|   : yyyyyy               |
-|   : yyyy                 |
-|   : yy                   |
-|   :                      |
-+---+----------------------+
++-[ RECORD 1 ]--------------+
+| ab | xx                   |
+|+   ;                      |
+|+c  ;                      |
+| a  | yyyyyyyyyyyyyyyyyy   |
+|+bc ;                      |
++-[ RECORD 2 ]--------------+
+| ab | xxxx                 |
+|+   : xxxxxx               |
+|+c  : xxxxxxxx             |
+|    : xxxxxxxxxx           |
+|    : xxxxxxxxxxxx         |
+|    : xxxxxxxxxxxxxx       |
+|    : xxxxxxxxxxxxxxxx     |
+|    : xxxxxxxxxxxxxxxxxx   |
+|    : xxxxxxxxxxxxxxxxxxxx |
+| a  | yyyyyyyyyyyyyyyy     |
+|+bc : yyyyyyyyyyyyyy       |
+|    : yyyyyyyyyyyy         |
+|    : yyyyyyyyyy           |
+|    : yyyyyyyy             |
+|    : yyyyyy               |
+|    : yyyy                 |
+|    : yy                   |
+|    :                      |
++----+----------------------+
+
+\pset format wrapped
+execute q;
++-[ RECORD 1 ]-----+
+| ab | xx          |
+|+   ;             |
+|+c  ;             |
+| a  | yyyyyyyyyyy |
+|+bc ; yyyyyyy     |
++-[ RECORD 2 ]-----+
+| ab | xxxx        |
+|+   : xxxxxx      |
+|+c  : xxxxxxxx    |
+|    : xxxxxxxxxx  |
+|    : xxxxxxxxxxx |
+|    ; x           |
+|    : xxxxxxxxxxx |
+|    ; xxx         |
+|    : xxxxxxxxxxx |
+|    ; xxxxx       |
+|    : xxxxxxxxxxx |
+|    ; xxxxxxx     |
+|    : xxxxxxxxxxx |
+|    ; xxxxxxxxx   |
+| a  | yyyyyyyyyyy |
+|+bc ; yyyyy       |
+|    : yyyyyyyyyyy |
+|    ; yyy         |
+|    : yyyyyyyyyyy |
+|    ; y           |
+|    : yyyyyyyyyy  |
+|    : yyyyyyyy    |
+|    : yyyyyy      |
+|    : yyyy        |
+|    : yy          |
+|    :             |
++----+-------------+
+
+deallocate q;
+-- test single-line header and data
+prepare q as select repeat('x',2*n) as "abcde", repeat('y',20-2*n) as "a" from generate_series(1,10) as n;
+\pset linestyle ascii
+\pset expanded off
+\pset columns 40
+\pset border 0
+\pset format unaligned
+execute q;
+abcde|a
+xx|yyyyyyyyyyyyyyyyyy
+xxxx|yyyyyyyyyyyyyyyy
+xxxxxx|yyyyyyyyyyyyyy
+xxxxxxxx|yyyyyyyyyyyy
+xxxxxxxxxx|yyyyyyyyyy
+xxxxxxxxxxxx|yyyyyyyy
+xxxxxxxxxxxxxx|yyyyyy
+xxxxxxxxxxxxxxxx|yyyy
+xxxxxxxxxxxxxxxxxx|yy
+xxxxxxxxxxxxxxxxxxxx|
+(10 rows)
+\pset format aligned
+execute q;
+       abcde                 a          
+-------------------- ------------------
+xx                   yyyyyyyyyyyyyyyyyy
+xxxx                 yyyyyyyyyyyyyyyy
+xxxxxx               yyyyyyyyyyyyyy
+xxxxxxxx             yyyyyyyyyyyy
+xxxxxxxxxx           yyyyyyyyyy
+xxxxxxxxxxxx         yyyyyyyy
+xxxxxxxxxxxxxx       yyyyyy
+xxxxxxxxxxxxxxxx     yyyy
+xxxxxxxxxxxxxxxxxx   yy
+xxxxxxxxxxxxxxxxxxxx 
+(10 rows)
+
+\pset format wrapped
+execute q;
+       abcde                 a          
+-------------------- ------------------
+xx                   yyyyyyyyyyyyyyyyyy
+xxxx                 yyyyyyyyyyyyyyyy
+xxxxxx               yyyyyyyyyyyyyy
+xxxxxxxx             yyyyyyyyyyyy
+xxxxxxxxxx           yyyyyyyyyy
+xxxxxxxxxxxx         yyyyyyyy
+xxxxxxxxxxxxxx       yyyyyy
+xxxxxxxxxxxxxxxx     yyyy
+xxxxxxxxxxxxxxxxxx   yy
+xxxxxxxxxxxxxxxxxxxx 
+(10 rows)
+
+\pset border 1
+\pset format unaligned
+execute q;
+abcde|a
+xx|yyyyyyyyyyyyyyyyyy
+xxxx|yyyyyyyyyyyyyyyy
+xxxxxx|yyyyyyyyyyyyyy
+xxxxxxxx|yyyyyyyyyyyy
+xxxxxxxxxx|yyyyyyyyyy
+xxxxxxxxxxxx|yyyyyyyy
+xxxxxxxxxxxxxx|yyyyyy
+xxxxxxxxxxxxxxxx|yyyy
+xxxxxxxxxxxxxxxxxx|yy
+xxxxxxxxxxxxxxxxxxxx|
+(10 rows)
+\pset format aligned
+execute q;
+        abcde         |         a          
+----------------------+--------------------
+ xx                   | yyyyyyyyyyyyyyyyyy
+ xxxx                 | yyyyyyyyyyyyyyyy
+ xxxxxx               | yyyyyyyyyyyyyy
+ xxxxxxxx             | yyyyyyyyyyyy
+ xxxxxxxxxx           | yyyyyyyyyy
+ xxxxxxxxxxxx         | yyyyyyyy
+ xxxxxxxxxxxxxx       | yyyyyy
+ xxxxxxxxxxxxxxxx     | yyyy
+ xxxxxxxxxxxxxxxxxx   | yy
+ xxxxxxxxxxxxxxxxxxxx | 
+(10 rows)
+
+\pset format wrapped
+execute q;
+        abcde        |        a         
+---------------------+------------------
+ xx                  | yyyyyyyyyyyyyyyy.
+                     |.yy
+ xxxx                | yyyyyyyyyyyyyyyy
+ xxxxxx              | yyyyyyyyyyyyyy
+ xxxxxxxx            | yyyyyyyyyyyy
+ xxxxxxxxxx          | yyyyyyyyyy
+ xxxxxxxxxxxx        | yyyyyyyy
+ xxxxxxxxxxxxxx      | yyyyyy
+ xxxxxxxxxxxxxxxx    | yyyy
+ xxxxxxxxxxxxxxxxxx  | yy
+ xxxxxxxxxxxxxxxxxxx.| 
+.x                   | 
+(10 rows)
+
+\pset border 2
+\pset format unaligned
+execute q;
+abcde|a
+xx|yyyyyyyyyyyyyyyyyy
+xxxx|yyyyyyyyyyyyyyyy
+xxxxxx|yyyyyyyyyyyyyy
+xxxxxxxx|yyyyyyyyyyyy
+xxxxxxxxxx|yyyyyyyyyy
+xxxxxxxxxxxx|yyyyyyyy
+xxxxxxxxxxxxxx|yyyyyy
+xxxxxxxxxxxxxxxx|yyyy
+xxxxxxxxxxxxxxxxxx|yy
+xxxxxxxxxxxxxxxxxxxx|
+(10 rows)
+\pset format aligned
+execute q;
++----------------------+--------------------+
+|        abcde         |         a          |
++----------------------+--------------------+
+| xx                   | yyyyyyyyyyyyyyyyyy |
+| xxxx                 | yyyyyyyyyyyyyyyy   |
+| xxxxxx               | yyyyyyyyyyyyyy     |
+| xxxxxxxx             | yyyyyyyyyyyy       |
+| xxxxxxxxxx           | yyyyyyyyyy         |
+| xxxxxxxxxxxx         | yyyyyyyy           |
+| xxxxxxxxxxxxxx       | yyyyyy             |
+| xxxxxxxxxxxxxxxx     | yyyy               |
+| xxxxxxxxxxxxxxxxxx   | yy                 |
+| xxxxxxxxxxxxxxxxxxxx |                    |
++----------------------+--------------------+
+(10 rows)
+
+\pset format wrapped
+execute q;
++--------------------+-----------------+
+|       abcde        |        a        |
++--------------------+-----------------+
+| xx                 | yyyyyyyyyyyyyyy.|
+|                    |.yyy             |
+| xxxx               | yyyyyyyyyyyyyyy.|
+|                    |.y               |
+| xxxxxx             | yyyyyyyyyyyyyy  |
+| xxxxxxxx           | yyyyyyyyyyyy    |
+| xxxxxxxxxx         | yyyyyyyyyy      |
+| xxxxxxxxxxxx       | yyyyyyyy        |
+| xxxxxxxxxxxxxx     | yyyyyy          |
+| xxxxxxxxxxxxxxxx   | yyyy            |
+| xxxxxxxxxxxxxxxxxx | yy              |
+| xxxxxxxxxxxxxxxxxx.|                 |
+|.xx                 |                 |
++--------------------+-----------------+
+(10 rows)
+
+\pset expanded on
+\pset columns 20
+\pset border 0
+\pset format unaligned
+execute q;
+abcde|xx
+a|yyyyyyyyyyyyyyyyyy
+
+abcde|xxxx
+a|yyyyyyyyyyyyyyyy
+
+abcde|xxxxxx
+a|yyyyyyyyyyyyyy
+
+abcde|xxxxxxxx
+a|yyyyyyyyyyyy
+
+abcde|xxxxxxxxxx
+a|yyyyyyyyyy
+
+abcde|xxxxxxxxxxxx
+a|yyyyyyyy
+
+abcde|xxxxxxxxxxxxxx
+a|yyyyyy
+
+abcde|xxxxxxxxxxxxxxxx
+a|yyyy
+
+abcde|xxxxxxxxxxxxxxxxxx
+a|yy
+
+abcde|xxxxxxxxxxxxxxxxxxxx
+a|
+\pset format aligned
+execute q;
+* Record 1               
+abcde xx                  
+a     yyyyyyyyyyyyyyyyyy  
+* Record 2               
+abcde xxxx                
+a     yyyyyyyyyyyyyyyy    
+* Record 3               
+abcde xxxxxx              
+a     yyyyyyyyyyyyyy      
+* Record 4               
+abcde xxxxxxxx            
+a     yyyyyyyyyyyy        
+* Record 5               
+abcde xxxxxxxxxx          
+a     yyyyyyyyyy          
+* Record 6               
+abcde xxxxxxxxxxxx        
+a     yyyyyyyy            
+* Record 7               
+abcde xxxxxxxxxxxxxx      
+a     yyyyyy              
+* Record 8               
+abcde xxxxxxxxxxxxxxxx    
+a     yyyy                
+* Record 9               
+abcde xxxxxxxxxxxxxxxxxx  
+a     yy                  
+* Record 10              
+abcde xxxxxxxxxxxxxxxxxxxx
+a                         
+
+\pset format wrapped
+execute q;
+* Record 1        
+abcde xx            
+a     yyyyyyyyyyyyy.
+     .yyyyy         
+* Record 2        
+abcde xxxx          
+a     yyyyyyyyyyyyy.
+     .yyy           
+* Record 3        
+abcde xxxxxx        
+a     yyyyyyyyyyyyy.
+     .y             
+* Record 4        
+abcde xxxxxxxx      
+a     yyyyyyyyyyyy  
+* Record 5        
+abcde xxxxxxxxxx    
+a     yyyyyyyyyy    
+* Record 6        
+abcde xxxxxxxxxxxx  
+a     yyyyyyyy      
+* Record 7        
+abcde xxxxxxxxxxxxx.
+     .x             
+a     yyyyyy        
+* Record 8        
+abcde xxxxxxxxxxxxx.
+     .xxx           
+a     yyyy          
+* Record 9        
+abcde xxxxxxxxxxxxx.
+     .xxxxx         
+a     yy            
+* Record 10       
+abcde xxxxxxxxxxxxx.
+     .xxxxxxx       
+a                   
+
+\pset border 1
+\pset format unaligned
+execute q;
+abcde|xx
+a|yyyyyyyyyyyyyyyyyy
+
+abcde|xxxx
+a|yyyyyyyyyyyyyyyy
+
+abcde|xxxxxx
+a|yyyyyyyyyyyyyy
+
+abcde|xxxxxxxx
+a|yyyyyyyyyyyy
+
+abcde|xxxxxxxxxx
+a|yyyyyyyyyy
+
+abcde|xxxxxxxxxxxx
+a|yyyyyyyy
+
+abcde|xxxxxxxxxxxxxx
+a|yyyyyy
+
+abcde|xxxxxxxxxxxxxxxx
+a|yyyy
+
+abcde|xxxxxxxxxxxxxxxxxx
+a|yy
+
+abcde|xxxxxxxxxxxxxxxxxxxx
+a|
+\pset format aligned
+execute q;
+-[ RECORD 1 ]-----------------
+ abcde | xx                   
+ a     | yyyyyyyyyyyyyyyyyy   
+-[ RECORD 2 ]-----------------
+ abcde | xxxx                 
+ a     | yyyyyyyyyyyyyyyy     
+-[ RECORD 3 ]-----------------
+ abcde | xxxxxx               
+ a     | yyyyyyyyyyyyyy       
+-[ RECORD 4 ]-----------------
+ abcde | xxxxxxxx             
+ a     | yyyyyyyyyyyy         
+-[ RECORD 5 ]-----------------
+ abcde | xxxxxxxxxx           
+ a     | yyyyyyyyyy           
+-[ RECORD 6 ]-----------------
+ abcde | xxxxxxxxxxxx         
+ a     | yyyyyyyy             
+-[ RECORD 7 ]-----------------
+ abcde | xxxxxxxxxxxxxx       
+ a     | yyyyyy               
+-[ RECORD 8 ]-----------------
+ abcde | xxxxxxxxxxxxxxxx     
+ a     | yyyy                 
+-[ RECORD 9 ]-----------------
+ abcde | xxxxxxxxxxxxxxxxxx   
+ a     | yy                   
+-[ RECORD 10 ]----------------
+ abcde | xxxxxxxxxxxxxxxxxxxx 
+ a     |                      
+
+\pset format wrapped
+execute q;
+-[ RECORD 1 ]-------
+ abcde | xx         
+ a     | yyyyyyyyyy.
+       |.yyyyyyyy   
+-[ RECORD 2 ]-------
+ abcde | xxxx       
+ a     | yyyyyyyyyy.
+       |.yyyyyy     
+-[ RECORD 3 ]-------
+ abcde | xxxxxx     
+ a     | yyyyyyyyyy.
+       |.yyyy       
+-[ RECORD 4 ]-------
+ abcde | xxxxxxxx   
+ a     | yyyyyyyyyy.
+       |.yy         
+-[ RECORD 5 ]-------
+ abcde | xxxxxxxxxx 
+ a     | yyyyyyyyyy 
+-[ RECORD 6 ]-------
+ abcde | xxxxxxxxxx.
+       |.xx         
+ a     | yyyyyyyy   
+-[ RECORD 7 ]-------
+ abcde | xxxxxxxxxx.
+       |.xxxx       
+ a     | yyyyyy     
+-[ RECORD 8 ]-------
+ abcde | xxxxxxxxxx.
+       |.xxxxxx     
+ a     | yyyy       
+-[ RECORD 9 ]-------
+ abcde | xxxxxxxxxx.
+       |.xxxxxxxx   
+ a     | yy         
+-[ RECORD 10 ]------
+ abcde | xxxxxxxxxx.
+       |.xxxxxxxxxx 
+ a     |            
+
+\pset border 2
+\pset format unaligned
+execute q;
+abcde|xx
+a|yyyyyyyyyyyyyyyyyy
+
+abcde|xxxx
+a|yyyyyyyyyyyyyyyy
+
+abcde|xxxxxx
+a|yyyyyyyyyyyyyy
+
+abcde|xxxxxxxx
+a|yyyyyyyyyyyy
+
+abcde|xxxxxxxxxx
+a|yyyyyyyyyy
+
+abcde|xxxxxxxxxxxx
+a|yyyyyyyy
+
+abcde|xxxxxxxxxxxxxx
+a|yyyyyy
+
+abcde|xxxxxxxxxxxxxxxx
+a|yyyy
+
+abcde|xxxxxxxxxxxxxxxxxx
+a|yy
+
+abcde|xxxxxxxxxxxxxxxxxxxx
+a|
+\pset format aligned
+execute q;
++-[ RECORD 1 ]-----------------+
+| abcde | xx                   |
+| a     | yyyyyyyyyyyyyyyyyy   |
++-[ RECORD 2 ]-----------------+
+| abcde | xxxx                 |
+| a     | yyyyyyyyyyyyyyyy     |
++-[ RECORD 3 ]-----------------+
+| abcde | xxxxxx               |
+| a     | yyyyyyyyyyyyyy       |
++-[ RECORD 4 ]-----------------+
+| abcde | xxxxxxxx             |
+| a     | yyyyyyyyyyyy         |
++-[ RECORD 5 ]-----------------+
+| abcde | xxxxxxxxxx           |
+| a     | yyyyyyyyyy           |
++-[ RECORD 6 ]-----------------+
+| abcde | xxxxxxxxxxxx         |
+| a     | yyyyyyyy             |
++-[ RECORD 7 ]-----------------+
+| abcde | xxxxxxxxxxxxxx       |
+| a     | yyyyyy               |
++-[ RECORD 8 ]-----------------+
+| abcde | xxxxxxxxxxxxxxxx     |
+| a     | yyyy                 |
++-[ RECORD 9 ]-----------------+
+| abcde | xxxxxxxxxxxxxxxxxx   |
+| a     | yy                   |
++-[ RECORD 10 ]----------------+
+| abcde | xxxxxxxxxxxxxxxxxxxx |
+| a     |                      |
++-------+----------------------+
+
+\pset format wrapped
+execute q;
++-[ RECORD 1 ]-----+
+| abcde | xx       |
+| a     | yyyyyyyy.|
+|       |.yyyyyyyy.|
+|       |.yy       |
++-[ RECORD 2 ]-----+
+| abcde | xxxx     |
+| a     | yyyyyyyy.|
+|       |.yyyyyyyy |
++-[ RECORD 3 ]-----+
+| abcde | xxxxxx   |
+| a     | yyyyyyyy.|
+|       |.yyyyyy   |
++-[ RECORD 4 ]-----+
+| abcde | xxxxxxxx |
+| a     | yyyyyyyy.|
+|       |.yyyy     |
++-[ RECORD 5 ]-----+
+| abcde | xxxxxxxx.|
+|       |.xx       |
+| a     | yyyyyyyy.|
+|       |.yy       |
++-[ RECORD 6 ]-----+
+| abcde | xxxxxxxx.|
+|       |.xxxx     |
+| a     | yyyyyyyy |
++-[ RECORD 7 ]-----+
+| abcde | xxxxxxxx.|
+|       |.xxxxxx   |
+| a     | yyyyyy   |
++-[ RECORD 8 ]-----+
+| abcde | xxxxxxxx.|
+|       |.xxxxxxxx |
+| a     | yyyy     |
++-[ RECORD 9 ]-----+
+| abcde | xxxxxxxx.|
+|       |.xxxxxxxx.|
+|       |.xx       |
+| a     | yy       |
++-[ RECORD 10 ]----+
+| abcde | xxxxxxxx.|
+|       |.xxxxxxxx.|
+|       |.xxxx     |
+| a     |          |
++-------+----------+
+
+\pset linestyle old-ascii
+\pset expanded off
+\pset columns 40
+\pset border 0
+\pset format unaligned
+execute q;
+abcde|a
+xx|yyyyyyyyyyyyyyyyyy
+xxxx|yyyyyyyyyyyyyyyy
+xxxxxx|yyyyyyyyyyyyyy
+xxxxxxxx|yyyyyyyyyyyy
+xxxxxxxxxx|yyyyyyyyyy
+xxxxxxxxxxxx|yyyyyyyy
+xxxxxxxxxxxxxx|yyyyyy
+xxxxxxxxxxxxxxxx|yyyy
+xxxxxxxxxxxxxxxxxx|yy
+xxxxxxxxxxxxxxxxxxxx|
+(10 rows)
+\pset format aligned
+execute q;
+       abcde                 a         
+-------------------- ------------------
+xx                   yyyyyyyyyyyyyyyyyy
+xxxx                 yyyyyyyyyyyyyyyy
+xxxxxx               yyyyyyyyyyyyyy
+xxxxxxxx             yyyyyyyyyyyy
+xxxxxxxxxx           yyyyyyyyyy
+xxxxxxxxxxxx         yyyyyyyy
+xxxxxxxxxxxxxx       yyyyyy
+xxxxxxxxxxxxxxxx     yyyy
+xxxxxxxxxxxxxxxxxx   yy
+xxxxxxxxxxxxxxxxxxxx 
+(10 rows)
+
+\pset format wrapped
+execute q;
+       abcde                 a         
+-------------------- ------------------
+xx                   yyyyyyyyyyyyyyyyyy
+xxxx                 yyyyyyyyyyyyyyyy
+xxxxxx               yyyyyyyyyyyyyy
+xxxxxxxx             yyyyyyyyyyyy
+xxxxxxxxxx           yyyyyyyyyy
+xxxxxxxxxxxx         yyyyyyyy
+xxxxxxxxxxxxxx       yyyyyy
+xxxxxxxxxxxxxxxx     yyyy
+xxxxxxxxxxxxxxxxxx   yy
+xxxxxxxxxxxxxxxxxxxx 
+(10 rows)
+
+\pset border 1
+\pset format unaligned
+execute q;
+abcde|a
+xx|yyyyyyyyyyyyyyyyyy
+xxxx|yyyyyyyyyyyyyyyy
+xxxxxx|yyyyyyyyyyyyyy
+xxxxxxxx|yyyyyyyyyyyy
+xxxxxxxxxx|yyyyyyyyyy
+xxxxxxxxxxxx|yyyyyyyy
+xxxxxxxxxxxxxx|yyyyyy
+xxxxxxxxxxxxxxxx|yyyy
+xxxxxxxxxxxxxxxxxx|yy
+xxxxxxxxxxxxxxxxxxxx|
+(10 rows)
+\pset format aligned
+execute q;
+        abcde         |         a          
+----------------------+--------------------
+ xx                   | yyyyyyyyyyyyyyyyyy
+ xxxx                 | yyyyyyyyyyyyyyyy
+ xxxxxx               | yyyyyyyyyyyyyy
+ xxxxxxxx             | yyyyyyyyyyyy
+ xxxxxxxxxx           | yyyyyyyyyy
+ xxxxxxxxxxxx         | yyyyyyyy
+ xxxxxxxxxxxxxx       | yyyyyy
+ xxxxxxxxxxxxxxxx     | yyyy
+ xxxxxxxxxxxxxxxxxx   | yy
+ xxxxxxxxxxxxxxxxxxxx | 
+(10 rows)
+
+\pset format wrapped
+execute q;
+        abcde        |        a         
+---------------------+------------------
+ xx                  | yyyyyyyyyyyyyyyy 
+                     ; yy
+ xxxx                | yyyyyyyyyyyyyyyy
+ xxxxxx              | yyyyyyyyyyyyyy
+ xxxxxxxx            | yyyyyyyyyyyy
+ xxxxxxxxxx          | yyyyyyyyyy
+ xxxxxxxxxxxx        | yyyyyyyy
+ xxxxxxxxxxxxxx      | yyyyyy
+ xxxxxxxxxxxxxxxx    | yyyy
+ xxxxxxxxxxxxxxxxxx  | yy
+ xxxxxxxxxxxxxxxxxxx | 
+ x                     
+(10 rows)
+
+\pset border 2
+\pset format unaligned
+execute q;
+abcde|a
+xx|yyyyyyyyyyyyyyyyyy
+xxxx|yyyyyyyyyyyyyyyy
+xxxxxx|yyyyyyyyyyyyyy
+xxxxxxxx|yyyyyyyyyyyy
+xxxxxxxxxx|yyyyyyyyyy
+xxxxxxxxxxxx|yyyyyyyy
+xxxxxxxxxxxxxx|yyyyyy
+xxxxxxxxxxxxxxxx|yyyy
+xxxxxxxxxxxxxxxxxx|yy
+xxxxxxxxxxxxxxxxxxxx|
+(10 rows)
+\pset format aligned
+execute q;
++----------------------+--------------------+
+|        abcde         |         a          |
++----------------------+--------------------+
+| xx                   | yyyyyyyyyyyyyyyyyy |
+| xxxx                 | yyyyyyyyyyyyyyyy   |
+| xxxxxx               | yyyyyyyyyyyyyy     |
+| xxxxxxxx             | yyyyyyyyyyyy       |
+| xxxxxxxxxx           | yyyyyyyyyy         |
+| xxxxxxxxxxxx         | yyyyyyyy           |
+| xxxxxxxxxxxxxx       | yyyyyy             |
+| xxxxxxxxxxxxxxxx     | yyyy               |
+| xxxxxxxxxxxxxxxxxx   | yy                 |
+| xxxxxxxxxxxxxxxxxxxx |                    |
++----------------------+--------------------+
+(10 rows)
+
+\pset format wrapped
+execute q;
++--------------------+-----------------+
+|       abcde        |        a        |
++--------------------+-----------------+
+| xx                 | yyyyyyyyyyyyyyy |
+|                    ; yyy             |
+| xxxx               | yyyyyyyyyyyyyyy |
+|                    ; y               |
+| xxxxxx             | yyyyyyyyyyyyyy  |
+| xxxxxxxx           | yyyyyyyyyyyy    |
+| xxxxxxxxxx         | yyyyyyyyyy      |
+| xxxxxxxxxxxx       | yyyyyyyy        |
+| xxxxxxxxxxxxxx     | yyyyyy          |
+| xxxxxxxxxxxxxxxx   | yyyy            |
+| xxxxxxxxxxxxxxxxxx | yy              |
+| xxxxxxxxxxxxxxxxxx |                 |
+| xx                                   |
++--------------------+-----------------+
+(10 rows)
+
+\pset expanded on
+\pset columns 20
+\pset border 0
+\pset format unaligned
+execute q;
+abcde|xx
+a|yyyyyyyyyyyyyyyyyy
+
+abcde|xxxx
+a|yyyyyyyyyyyyyyyy
+
+abcde|xxxxxx
+a|yyyyyyyyyyyyyy
+
+abcde|xxxxxxxx
+a|yyyyyyyyyyyy
+
+abcde|xxxxxxxxxx
+a|yyyyyyyyyy
+
+abcde|xxxxxxxxxxxx
+a|yyyyyyyy
+
+abcde|xxxxxxxxxxxxxx
+a|yyyyyy
+
+abcde|xxxxxxxxxxxxxxxx
+a|yyyy
+
+abcde|xxxxxxxxxxxxxxxxxx
+a|yy
+
+abcde|xxxxxxxxxxxxxxxxxxxx
+a|
+\pset format aligned
+execute q;
+* Record 1               
+abcde xx                  
+a     yyyyyyyyyyyyyyyyyy  
+* Record 2               
+abcde xxxx                
+a     yyyyyyyyyyyyyyyy    
+* Record 3               
+abcde xxxxxx              
+a     yyyyyyyyyyyyyy      
+* Record 4               
+abcde xxxxxxxx            
+a     yyyyyyyyyyyy        
+* Record 5               
+abcde xxxxxxxxxx          
+a     yyyyyyyyyy          
+* Record 6               
+abcde xxxxxxxxxxxx        
+a     yyyyyyyy            
+* Record 7               
+abcde xxxxxxxxxxxxxx      
+a     yyyyyy              
+* Record 8               
+abcde xxxxxxxxxxxxxxxx    
+a     yyyy                
+* Record 9               
+abcde xxxxxxxxxxxxxxxxxx  
+a     yy                  
+* Record 10              
+abcde xxxxxxxxxxxxxxxxxxxx
+a                         
+
+\pset format wrapped
+execute q;
+* Record 1         
+abcde xx            
+a     yyyyyyyyyyyyyy
+      yyyy          
+* Record 2         
+abcde xxxx          
+a     yyyyyyyyyyyyyy
+      yy            
+* Record 3         
+abcde xxxxxx        
+a     yyyyyyyyyyyyyy
+* Record 4         
+abcde xxxxxxxx      
+a     yyyyyyyyyyyy  
+* Record 5         
+abcde xxxxxxxxxx    
+a     yyyyyyyyyy    
+* Record 6         
+abcde xxxxxxxxxxxx  
+a     yyyyyyyy      
+* Record 7         
+abcde xxxxxxxxxxxxxx
+a     yyyyyy        
+* Record 8         
+abcde xxxxxxxxxxxxxx
+      xx            
+a     yyyy          
+* Record 9         
+abcde xxxxxxxxxxxxxx
+      xxxx          
+a     yy            
+* Record 10        
+abcde xxxxxxxxxxxxxx
+      xxxxxx        
+a                   
+
+\pset border 1
+\pset format unaligned
+execute q;
+abcde|xx
+a|yyyyyyyyyyyyyyyyyy
+
+abcde|xxxx
+a|yyyyyyyyyyyyyyyy
+
+abcde|xxxxxx
+a|yyyyyyyyyyyyyy
+
+abcde|xxxxxxxx
+a|yyyyyyyyyyyy
+
+abcde|xxxxxxxxxx
+a|yyyyyyyyyy
+
+abcde|xxxxxxxxxxxx
+a|yyyyyyyy
+
+abcde|xxxxxxxxxxxxxx
+a|yyyyyy
+
+abcde|xxxxxxxxxxxxxxxx
+a|yyyy
+
+abcde|xxxxxxxxxxxxxxxxxx
+a|yy
+
+abcde|xxxxxxxxxxxxxxxxxxxx
+a|
+\pset format aligned
+execute q;
+-[ RECORD 1 ]-----------------
+ abcde | xx                   
+ a     | yyyyyyyyyyyyyyyyyy   
+-[ RECORD 2 ]-----------------
+ abcde | xxxx                 
+ a     | yyyyyyyyyyyyyyyy     
+-[ RECORD 3 ]-----------------
+ abcde | xxxxxx               
+ a     | yyyyyyyyyyyyyy       
+-[ RECORD 4 ]-----------------
+ abcde | xxxxxxxx             
+ a     | yyyyyyyyyyyy         
+-[ RECORD 5 ]-----------------
+ abcde | xxxxxxxxxx           
+ a     | yyyyyyyyyy           
+-[ RECORD 6 ]-----------------
+ abcde | xxxxxxxxxxxx         
+ a     | yyyyyyyy             
+-[ RECORD 7 ]-----------------
+ abcde | xxxxxxxxxxxxxx       
+ a     | yyyyyy               
+-[ RECORD 8 ]-----------------
+ abcde | xxxxxxxxxxxxxxxx     
+ a     | yyyy                 
+-[ RECORD 9 ]-----------------
+ abcde | xxxxxxxxxxxxxxxxxx   
+ a     | yy                   
+-[ RECORD 10 ]----------------
+ abcde | xxxxxxxxxxxxxxxxxxxx 
+ a     |                      
+
+\pset format wrapped
+execute q;
+-[ RECORD 1 ]-------
+ abcde | xx         
+ a     | yyyyyyyyyy 
+       ; yyyyyyyy   
+-[ RECORD 2 ]-------
+ abcde | xxxx       
+ a     | yyyyyyyyyy 
+       ; yyyyyy     
+-[ RECORD 3 ]-------
+ abcde | xxxxxx     
+ a     | yyyyyyyyyy 
+       ; yyyy       
+-[ RECORD 4 ]-------
+ abcde | xxxxxxxx   
+ a     | yyyyyyyyyy 
+       ; yy         
+-[ RECORD 5 ]-------
+ abcde | xxxxxxxxxx 
+ a     | yyyyyyyyyy 
+-[ RECORD 6 ]-------
+ abcde | xxxxxxxxxx 
+       ; xx         
+ a     | yyyyyyyy   
+-[ RECORD 7 ]-------
+ abcde | xxxxxxxxxx 
+       ; xxxx       
+ a     | yyyyyy     
+-[ RECORD 8 ]-------
+ abcde | xxxxxxxxxx 
+       ; xxxxxx     
+ a     | yyyy       
+-[ RECORD 9 ]-------
+ abcde | xxxxxxxxxx 
+       ; xxxxxxxx   
+ a     | yy         
+-[ RECORD 10 ]------
+ abcde | xxxxxxxxxx 
+       ; xxxxxxxxxx 
+ a     |            
+
+\pset border 2
+\pset format unaligned
+execute q;
+abcde|xx
+a|yyyyyyyyyyyyyyyyyy
+
+abcde|xxxx
+a|yyyyyyyyyyyyyyyy
+
+abcde|xxxxxx
+a|yyyyyyyyyyyyyy
+
+abcde|xxxxxxxx
+a|yyyyyyyyyyyy
+
+abcde|xxxxxxxxxx
+a|yyyyyyyyyy
+
+abcde|xxxxxxxxxxxx
+a|yyyyyyyy
+
+abcde|xxxxxxxxxxxxxx
+a|yyyyyy
+
+abcde|xxxxxxxxxxxxxxxx
+a|yyyy
+
+abcde|xxxxxxxxxxxxxxxxxx
+a|yy
+
+abcde|xxxxxxxxxxxxxxxxxxxx
+a|
+\pset format aligned
+execute q;
++-[ RECORD 1 ]-----------------+
+| abcde | xx                   |
+| a     | yyyyyyyyyyyyyyyyyy   |
++-[ RECORD 2 ]-----------------+
+| abcde | xxxx                 |
+| a     | yyyyyyyyyyyyyyyy     |
++-[ RECORD 3 ]-----------------+
+| abcde | xxxxxx               |
+| a     | yyyyyyyyyyyyyy       |
++-[ RECORD 4 ]-----------------+
+| abcde | xxxxxxxx             |
+| a     | yyyyyyyyyyyy         |
++-[ RECORD 5 ]-----------------+
+| abcde | xxxxxxxxxx           |
+| a     | yyyyyyyyyy           |
++-[ RECORD 6 ]-----------------+
+| abcde | xxxxxxxxxxxx         |
+| a     | yyyyyyyy             |
++-[ RECORD 7 ]-----------------+
+| abcde | xxxxxxxxxxxxxx       |
+| a     | yyyyyy               |
++-[ RECORD 8 ]-----------------+
+| abcde | xxxxxxxxxxxxxxxx     |
+| a     | yyyy                 |
++-[ RECORD 9 ]-----------------+
+| abcde | xxxxxxxxxxxxxxxxxx   |
+| a     | yy                   |
++-[ RECORD 10 ]----------------+
+| abcde | xxxxxxxxxxxxxxxxxxxx |
+| a     |                      |
++-------+----------------------+
 
 \pset format wrapped
 execute q;
 +-[ RECORD 1 ]-----+
-| a | xx           |
-|+  ;              |
-|+b ;              |
-| a | yyyyyyyyyyyy |
-|+b ; yyyyyy       |
+| abcde | xx       |
+| a     | yyyyyyyy |
+|       ; yyyyyyyy |
+|       ; yy       |
 +-[ RECORD 2 ]-----+
-| a | xxxx         |
-|+  : xxxxxx       |
-|+b : xxxxxxxx     |
-|   : xxxxxxxxxx   |
-|   : xxxxxxxxxxxx |
-|   : xxxxxxxxxxxx |
-|   ; xx           |
-|   : xxxxxxxxxxxx |
-|   ; xxxx         |
-|   : xxxxxxxxxxxx |
-|   ; xxxxxx       |
-|   : xxxxxxxxxxxx |
-|   ; xxxxxxxx     |
-| a | yyyyyyyyyyyy |
-|+b ; yyyy         |
-|   : yyyyyyyyyyyy |
-|   ; yy           |
-|   : yyyyyyyyyyyy |
-|   : yyyyyyyyyy   |
-|   : yyyyyyyy     |
-|   : yyyyyy       |
-|   : yyyy         |
-|   : yy           |
-|   :              |
-+---+--------------+
+| abcde | xxxx     |
+| a     | yyyyyyyy |
+|       ; yyyyyyyy |
++-[ RECORD 3 ]-----+
+| abcde | xxxxxx   |
+| a     | yyyyyyyy |
+|       ; yyyyyy   |
++-[ RECORD 4 ]-----+
+| abcde | xxxxxxxx |
+| a     | yyyyyyyy |
+|       ; yyyy     |
++-[ RECORD 5 ]-----+
+| abcde | xxxxxxxx |
+|       ; xx       |
+| a     | yyyyyyyy |
+|       ; yy       |
++-[ RECORD 6 ]-----+
+| abcde | xxxxxxxx |
+|       ; xxxx     |
+| a     | yyyyyyyy |
++-[ RECORD 7 ]-----+
+| abcde | xxxxxxxx |
+|       ; xxxxxx   |
+| a     | yyyyyy   |
++-[ RECORD 8 ]-----+
+| abcde | xxxxxxxx |
+|       ; xxxxxxxx |
+| a     | yyyy     |
++-[ RECORD 9 ]-----+
+| abcde | xxxxxxxx |
+|       ; xxxxxxxx |
+|       ; xx       |
+| a     | yy       |
++-[ RECORD 10 ]----+
+| abcde | xxxxxxxx |
+|       ; xxxxxxxx |
+|       ; xxxx     |
+| a     |          |
++-------+----------+
 
 deallocate q;
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index a7d5eeb..5ccc68f 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -42,10 +42,10 @@ select 10 as test01, 20 as test02 from generate_series(1,0) \gset
 \pset
 
 -- test multi-line headers, wrapping, and newline indicators
-prepare q as select array_to_string(array_agg(repeat('x',2*n)),E'\n') as "a
+prepare q as select array_to_string(array_agg(repeat('x',2*n)),E'\n') as "ab
 
-b", array_to_string(array_agg(repeat('y',20-2*n)),E'\n') as "a
-b" from generate_series(1,10) as n(n) group by n>1 ;
+c", array_to_string(array_agg(repeat('y',20-2*n)),E'\n') as "a
+bc" from generate_series(1,10) as n(n) group by n>1 ;
 
 \pset linestyle ascii
 
@@ -160,3 +160,119 @@ execute q;
 execute q;
 
 deallocate q;
+
+-- test single-line header and data
+prepare q as select repeat('x',2*n) as "0123456789abcdef", repeat('y',20-2*n) as "0123456789" from generate_series(1,10) as n;
+
+\pset linestyle ascii
+
+\pset expanded off
+\pset columns 40
+
+\pset border 0
+\pset format unaligned
+execute q;
+\pset format aligned
+execute q;
+\pset format wrapped
+execute q;
+
+\pset border 1
+\pset format unaligned
+execute q;
+\pset format aligned
+execute q;
+\pset format wrapped
+execute q;
+
+\pset border 2
+\pset format unaligned
+execute q;
+\pset format aligned
+execute q;
+\pset format wrapped
+execute q;
+
+\pset expanded on
+\pset columns 20
+
+\pset border 0
+\pset format unaligned
+execute q;
+\pset format aligned
+execute q;
+\pset format wrapped
+execute q;
+
+\pset border 1
+\pset format unaligned
+execute q;
+\pset format aligned
+execute q;
+\pset format wrapped
+execute q;
+
+\pset border 2
+\pset format unaligned
+execute q;
+\pset format aligned
+execute q;
+\pset format wrapped
+execute q;
+
+\pset linestyle old-ascii
+
+\pset expanded off
+\pset columns 40
+
+\pset border 0
+\pset format unaligned
+execute q;
+\pset format aligned
+execute q;
+\pset format wrapped
+execute q;
+
+\pset border 1
+\pset format unaligned
+execute q;
+\pset format aligned
+execute q;
+\pset format wrapped
+execute q;
+
+\pset border 2
+\pset format unaligned
+execute q;
+\pset format aligned
+execute q;
+\pset format wrapped
+execute q;
+
+\pset expanded on
+
+\pset border 0
+\pset format unaligned
+execute q;
+\pset format aligned
+execute q;
+\pset format wrapped
+execute q;
+
+\pset border 1
+\pset format unaligned
+execute q;
+\pset format aligned
+execute q;
+\pset format wrapped
+execute q;
+
+\pset border 2
+\pset format unaligned
+execute q;
+\pset format aligned
+execute q;
+\pset format wrapped
+execute q;
+
+deallocate q;
