diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index 62850d8..140b0e5 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -1258,45 +1258,74 @@ 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, + min_width, swidth; if (opt_border == 0) - swidth = 1; /* "header data" */ + { + /* + * For border = 0, one space in the middle. + */ + swidth = 1; + if ((hheight > 1) && + (dheight > 1) && + (format != &pg_asciiformat_old)) + swidth++; + } else if (opt_border == 1) - swidth = 3; /* "header | data" */ - else - swidth = 7; /* "| header | data |" */ - - /* Wrap to maximum width */ - width = dwidth + swidth + hwidth; - if ((output_columns > 0) && (width > output_columns)) { - dwidth = output_columns - hwidth - swidth; - width = output_columns; + /* + * For border = 1, one for the pipe (|) in the middle + * between the two spaces. + */ + swidth = 3; } + 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 + 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 (delta > 0) - dwidth += delta; + if (rwidth > min_width) + min_width = rwidth; } - else if (dwidth < 3) - dwidth = 3; + + /* Wrap to minimum width */ + width = hwidth + swidth + dwidth; + if ((width < min_width) || (output_columns < min_width)) + dwidth = min_width - hwidth - swidth; + else if (output_columns > 0) + /* + * Wrap to maximum width + */ + dwidth = output_columns - hwidth - swidth; + + if ((dheight > 1) && + (opt_border < 2) && + (format != &pg_asciiformat_old)) + dwidth--; /* for wrapping indicator */ } /* print records */ @@ -1356,33 +1385,71 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) { int swidth, twidth = hwidth + 1; + /* + * Left spacer or new line indicator + */ + if (((hheight > 1) && + (format == &pg_asciiformat_old)) || + (opt_border == 2)) + fputs(hline ? format->header_nl_left : " ", fout); - fputs(hline ? format->header_nl_left : " ", fout); + /* + * Header text + */ strlen_max_width(hlineptr[hline].ptr, &twidth, encoding); fprintf(fout, "%-s", hlineptr[hline].ptr); + /* + * Spacer + */ swidth = hwidth - twidth; if (swidth > 0) /* spacer */ 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) || + (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) + fputs(" ", fout); + else if ((format != &pg_asciiformat_old) && + (hheight > 1) && + (dheight > 1)) + fputs(" ", fout); hcomplete = 1; } } else { - /* Header exhausted but more data for column */ - fprintf(fout, "%*s", hwidth + 2, ""); + unsigned int ewidth = hwidth; + if (opt_border == 0) + { + if ((hheight > 1) && + (dheight > 1)) + ewidth++; + } + else if (opt_border == 1) + { + ewidth++; + if ((format == &pg_asciiformat_old) && + (hheight > 1) && + (dheight > 1)) + ewidth++; + } + else + ewidth += 2; + fprintf(fout, "%*s", ewidth, " "); } /* Separator */ @@ -1397,17 +1464,25 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) else fputs(format->midvrule_blank, fout); } + else if (format == &pg_asciiformat_old) + fputs(format->midvrule_blank, fout); /* Data */ if (!dcomplete) { - int target_width, + int target_width = dwidth, bytes_to_output, swidth; + /* + * Left spacer on new line indicator + */ + if ((dheight > 1) && (format != &pg_asciiformat_old)) + { + fputs(!dcomplete && !offset ? " " : format->wrap_left, fout); + } + else if (opt_border > 0) + fputs(" ", fout); - fputs(!dcomplete && !offset ? " " : format->wrap_left, fout); - - target_width = dwidth; bytes_to_output = strlen_max_width(dlineptr[dline].ptr + offset, &target_width, encoding); fputnbytes(fout, (char *) (dlineptr[dline].ptr + offset), @@ -1419,17 +1494,21 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) /* spacer */ swidth = dwidth - 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 ((format != &pg_asciiformat_old) || + (opt_border == 2)) + fputs(format->wrap_right, fout); } else if (dlineptr[dline + 1].ptr) { /* reached a newline in the column */ - fputs(format->nl_right, fout); + if ((format != &pg_asciiformat_old) || + (opt_border == 2)) + fputs(format->nl_right, fout); dline++; offset = 0; chars_to_output = dlineptr[dline].width; @@ -1437,7 +1516,8 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) else { /* reached the end of the cell */ - fputs(" ", fout); + if (opt_border == 2) + fputs(" ", fout); dcomplete = 1; } diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out index c7dbd54..55cd215 100644 --- a/src/test/regress/expected/psql.out +++ b/src/test/regress/expected/psql.out @@ -306,59 +306,60 @@ yy \pset format aligned execute q; * Record 1 - a+ xx - + - b - a+ yyyyyyyyyyyyyyyyyy - b +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 + - +a+ xxxx + + + xxxxxx + +b xxxxxxxx + + xxxxxxxxxx + + xxxxxxxxxxxx + + xxxxxxxxxxxxxx + + xxxxxxxxxxxxxxxx + + xxxxxxxxxxxxxxxxxx + + xxxxxxxxxxxxxxxxxxxx +a+ yyyyyyyyyyyyyyyy + +b yyyyyyyyyyyyyy + + yyyyyyyyyyyy + + yyyyyyyyyy + + yyyyyyyy + + yyyyyy + + yyyy + + yy + + \pset format wrapped execute q; -* Record 1 - a+ 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 + - +* Record 1 +a+ xx + + +b +a+ yyyyyyyyyyyyyyyy. +b .yy +* 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 + + \pset border 1 \pset format unaligned @@ -393,60 +394,62 @@ yy \pset format aligned execute q; -[ RECORD 1 ]----------- - a+| xx - +| - b | - a+| yyyyyyyyyyyyyyyyyy - b | +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 + - | +a+| xxxx + + +| xxxxxx + +b | xxxxxxxx + + | xxxxxxxxxx + + | xxxxxxxxxxxx + + | xxxxxxxxxxxxxx + + | xxxxxxxxxxxxxxxx + + | xxxxxxxxxxxxxxxxxx + + | xxxxxxxxxxxxxxxxxxxx +a+| yyyyyyyyyyyyyyyy + +b | yyyyyyyyyyyyyy + + | yyyyyyyyyyyy + + | yyyyyyyyyy + + | yyyyyyyy + + | yyyyyy + + | yyyy + + | yy + + | \pset format wrapped execute q; --[ RECORD 1 ]------- - a+| xx - +| - b | - a+| yyyyyyyyyyyyyyyy. - b |.yy --[ 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 + - | +-[ RECORD 1 ]------ +a+| xx + +| +b | +a+| yyyyyyyyyyyyyyy. +b |.yyy +-[ RECORD 2 ]------ +a+| xxxx + + +| xxxxxx + +b | xxxxxxxx + + | xxxxxxxxxx + + | xxxxxxxxxxxx + + | xxxxxxxxxxxxxx + + | xxxxxxxxxxxxxxx. + |.x + + | xxxxxxxxxxxxxxx. + |.xxx + + | xxxxxxxxxxxxxxx. + |.xxxxx +a+| yyyyyyyyyyyyyyy. +b |.y + + | yyyyyyyyyyyyyy + + | yyyyyyyyyyyy + + | yyyyyyyyyy + + | yyyyyyyy + + | yyyyyy + + | yyyy + + | yy + + | \pset border 2 \pset format unaligned @@ -775,59 +778,59 @@ yy \pset format aligned execute q; * Record 1 - a xx + a xx + +b - a yyyyyyyyyyyyyyyyyy + 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 - + a xxxx ++ xxxxxx ++b xxxxxxxx + xxxxxxxxxx + xxxxxxxxxxxx + xxxxxxxxxxxxxx + xxxxxxxxxxxxxxxx + xxxxxxxxxxxxxxxxxx + xxxxxxxxxxxxxxxxxxxx + a yyyyyyyyyyyyyyyy ++b yyyyyyyyyyyyyy + yyyyyyyyyyyy + yyyyyyyyyy + yyyyyyyy + yyyyyy + yyyy + yy + \pset format wrapped execute q; * Record 1 - a xx + a xx + +b - a yyyyyyyyyyyyyyyyyy + 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 - + a xxxx ++ xxxxxx ++b xxxxxxxx + xxxxxxxxxx + xxxxxxxxxxxx + xxxxxxxxxxxxxx + xxxxxxxxxxxxxxxx + xxxxxxxxxxxxxxxxxx + xxxxxxxxxxxxxxxxxx + xx + a yyyyyyyyyyyyyyyy ++b yyyyyyyyyyyyyy + yyyyyyyyyyyy + yyyyyyyyyy + yyyyyyyy + yyyyyy + yyyy + yy + \pset border 1 \pset format unaligned @@ -862,60 +865,60 @@ yy \pset format aligned execute q; -[ RECORD 1 ]----------- - a | xx + a | xx + ; +b ; - a | yyyyyyyyyyyyyyyyyy + 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 - : + a | xxxx ++ : xxxxxx ++b : xxxxxxxx + : xxxxxxxxxx + : xxxxxxxxxxxx + : xxxxxxxxxxxxxx + : xxxxxxxxxxxxxxxx + : xxxxxxxxxxxxxxxxxx + : xxxxxxxxxxxxxxxxxxxx + a | yyyyyyyyyyyyyyyy ++b : yyyyyyyyyyyyyy + : yyyyyyyyyyyy + : yyyyyyyyyy + : yyyyyyyy + : yyyyyy + : yyyy + : yy + : \pset format wrapped execute q; -[ RECORD 1 ]------- - a | xx + a | xx + ; +b ; - a | yyyyyyyyyyyyyyyy -+b ; yy + a | yyyyyyyyyyyyyyyy ++b ; yy -[ 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 - : + a | xxxx ++ : xxxxxx ++b : xxxxxxxx + : xxxxxxxxxx + : xxxxxxxxxxxx + : xxxxxxxxxxxxxx + : xxxxxxxxxxxxxxxx + : xxxxxxxxxxxxxxxx + ; xx + : xxxxxxxxxxxxxxxx + ; xxxx + a | yyyyyyyyyyyyyyyy ++b : yyyyyyyyyyyyyy + : yyyyyyyyyyyy + : yyyyyyyyyy + : yyyyyyyy + : yyyyyy + : yyyy + : yy + : \pset border 2 \pset format unaligned @@ -1012,3 +1015,812 @@ execute q; +---+--------------+ deallocate q; +-- test single-line headers, wrapping, and newline indicators +prepare q as select array_to_string(array_agg(repeat('x',2*n)),E'\n') as "abcde", +array_to_string(array_agg(repeat('y',20-2*n)),E'\n') as "a" +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; +abcde|a +xx|yyyyyyyyyyyyyyyyyy +xxxx +xxxxxx +xxxxxxxx +xxxxxxxxxx +xxxxxxxxxxxx +xxxxxxxxxxxxxx +xxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxx|yyyyyyyyyyyyyyyy +yyyyyyyyyyyyyy +yyyyyyyyyyyy +yyyyyyyyyy +yyyyyyyy +yyyyyy +yyyy +yy + +(2 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 +(2 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 +(2 rows) + +\pset border 1 +\pset format unaligned +execute q; +abcde|a +xx|yyyyyyyyyyyyyyyyyy +xxxx +xxxxxx +xxxxxxxx +xxxxxxxxxx +xxxxxxxxxxxx +xxxxxxxxxxxxxx +xxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxx|yyyyyyyyyyyyyyyy +yyyyyyyyyyyyyy +yyyyyyyyyyyy +yyyyyyyyyy +yyyyyyyy +yyyyyy +yyyy +yy + +(2 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 | +(2 rows) + +\pset format wrapped +execute q; + abcde | a +-------------------+-------------------- + xx | yyyyyyyyyyyyyyyyyy + xxxx +| yyyyyyyyyyyyyyyy + + xxxxxx +| yyyyyyyyyyyyyy + + xxxxxxxx +| yyyyyyyyyyyy + + xxxxxxxxxx +| yyyyyyyyyy + + xxxxxxxxxxxx +| yyyyyyyy + + xxxxxxxxxxxxxx +| yyyyyy + + xxxxxxxxxxxxxxxx +| yyyy + + xxxxxxxxxxxxxxxxx.| yy + +.x +| + xxxxxxxxxxxxxxxxx.| +.xxx | +(2 rows) + +\pset border 2 +\pset format unaligned +execute q; +abcde|a +xx|yyyyyyyyyyyyyyyyyy +xxxx +xxxxxx +xxxxxxxx +xxxxxxxxxx +xxxxxxxxxxxx +xxxxxxxxxxxxxx +xxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxx|yyyyyyyyyyyyyyyy +yyyyyyyyyyyyyy +yyyyyyyyyyyy +yyyyyyyyyy +yyyyyyyy +yyyyyy +yyyy +yy + +(2 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 | | ++----------------------+--------------------+ +(2 rows) + +\pset format wrapped +execute q; ++-----------------+--------------------+ +| abcde | a | ++-----------------+--------------------+ +| xx | yyyyyyyyyyyyyyyyyy | +| xxxx +| yyyyyyyyyyyyyyyy +| +| xxxxxx +| yyyyyyyyyyyyyy +| +| xxxxxxxx +| yyyyyyyyyyyy +| +| xxxxxxxxxx +| yyyyyyyyyy +| +| xxxxxxxxxxxx +| yyyyyyyy +| +| xxxxxxxxxxxxxx +| yyyyyy +| +| xxxxxxxxxxxxxxx.| yyyy +| +|.x +| yy +| +| xxxxxxxxxxxxxxx.| | +|.xxx +| | +| xxxxxxxxxxxxxxx.| | +|.xxxxx | | ++-----------------+--------------------+ +(2 rows) + +\pset expanded on +\pset border 0 +\pset format unaligned +execute q; +abcde|xx +a|yyyyyyyyyyyyyyyyyy + +abcde|xxxx +xxxxxx +xxxxxxxx +xxxxxxxxxx +xxxxxxxxxxxx +xxxxxxxxxxxxxx +xxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxx +a|yyyyyyyyyyyyyyyy +yyyyyyyyyyyyyy +yyyyyyyyyyyy +yyyyyyyyyy +yyyyyyyy +yyyyyy +yyyy +yy + +\pset format aligned +execute q; +* Record 1 +abcde xx +a yyyyyyyyyyyyyyyyyy +* Record 2 +abcde xxxx + + xxxxxx + + xxxxxxxx + + xxxxxxxxxx + + xxxxxxxxxxxx + + xxxxxxxxxxxxxx + + xxxxxxxxxxxxxxxx + + xxxxxxxxxxxxxxxxxx + + xxxxxxxxxxxxxxxxxxxx +a yyyyyyyyyyyyyyyy + + yyyyyyyyyyyyyy + + yyyyyyyyyyyy + + yyyyyyyyyy + + yyyyyyyy + + yyyyyy + + yyyy + + yy + + + +\pset format wrapped +execute q; +* Record 1 +abcde xx +a yyyyyyyyyyyyyyyyyy +* Record 2 +abcde xxxx + + xxxxxx + + xxxxxxxx + + xxxxxxxxxx + + xxxxxxxxxxxx + + xxxxxxxxxxxxxx + + xxxxxxxxxxxxxxxx + + xxxxxxxxxxxxxxxxxx + + xxxxxxxxxxxxxxxxxxxx +a yyyyyyyyyyyyyyyy + + yyyyyyyyyyyyyy + + yyyyyyyyyyyy + + yyyyyyyyyy + + yyyyyyyy + + yyyyyy + + yyyy + + yy + + + +\pset border 1 +\pset format unaligned +execute q; +abcde|xx +a|yyyyyyyyyyyyyyyyyy + +abcde|xxxx +xxxxxx +xxxxxxxx +xxxxxxxxxx +xxxxxxxxxxxx +xxxxxxxxxxxxxx +xxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxx +a|yyyyyyyyyyyyyyyy +yyyyyyyyyyyyyy +yyyyyyyyyyyy +yyyyyyyyyy +yyyyyyyy +yyyyyy +yyyy +yy + +\pset format aligned +execute q; +-[ RECORD 1 ]--------------- +abcde | xx +a | yyyyyyyyyyyyyyyyyy +-[ RECORD 2 ]--------------- +abcde | xxxx + + | xxxxxx + + | xxxxxxxx + + | xxxxxxxxxx + + | xxxxxxxxxxxx + + | xxxxxxxxxxxxxx + + | xxxxxxxxxxxxxxxx + + | xxxxxxxxxxxxxxxxxx + + | xxxxxxxxxxxxxxxxxxxx +a | yyyyyyyyyyyyyyyy + + | yyyyyyyyyyyyyy + + | yyyyyyyyyyyy + + | yyyyyyyyyy + + | yyyyyyyy + + | yyyyyy + + | yyyy + + | yy + + | + +\pset format wrapped +execute q; +-[ RECORD 1 ]-------------------------- +abcde | xx +a | yyyyyyyyyyyyyyyyyy +-[ RECORD 2 ]-------------------------- +abcde | xxxx + + | xxxxxx + + | xxxxxxxx + + | xxxxxxxxxx + + | xxxxxxxxxxxx + + | xxxxxxxxxxxxxx + + | xxxxxxxxxxxxxxxx + + | xxxxxxxxxxxxxxxxxx + + | xxxxxxxxxxxxxxxxxxxx +a | yyyyyyyyyyyyyyyy + + | yyyyyyyyyyyyyy + + | yyyyyyyyyyyy + + | yyyyyyyyyy + + | yyyyyyyy + + | yyyyyy + + | yyyy + + | yy + + | + +\pset border 2 +\pset format unaligned +execute q; +abcde|xx +a|yyyyyyyyyyyyyyyyyy + +abcde|xxxx +xxxxxx +xxxxxxxx +xxxxxxxxxx +xxxxxxxxxxxx +xxxxxxxxxxxxxx +xxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxx +a|yyyyyyyyyyyyyyyy +yyyyyyyyyyyyyy +yyyyyyyyyyyy +yyyyyyyyyy +yyyyyyyy +yyyyyy +yyyy +yy + +\pset format aligned +execute q; ++-[ RECORD 1 ]-----------------+ +| abcde | xx | +| a | yyyyyyyyyyyyyyyyyy | ++-[ RECORD 2 ]-----------------+ +| abcde | xxxx +| +| | xxxxxx +| +| | xxxxxxxx +| +| | xxxxxxxxxx +| +| | xxxxxxxxxxxx +| +| | xxxxxxxxxxxxxx +| +| | xxxxxxxxxxxxxxxx +| +| | xxxxxxxxxxxxxxxxxx +| +| | xxxxxxxxxxxxxxxxxxxx | +| a | yyyyyyyyyyyyyyyy +| +| | yyyyyyyyyyyyyy +| +| | yyyyyyyyyyyy +| +| | yyyyyyyyyy +| +| | yyyyyyyy +| +| | yyyyyy +| +| | yyyy +| +| | yy +| +| | | ++-------+----------------------+ + +\pset format wrapped +execute q; ++-[ RECORD 1 ]-------------------------+ +| abcde | xx | +| a | yyyyyyyyyyyyyyyyyy | ++-[ RECORD 2 ]-------------------------+ +| abcde | xxxx +| +| | xxxxxx +| +| | xxxxxxxx +| +| | xxxxxxxxxx +| +| | xxxxxxxxxxxx +| +| | xxxxxxxxxxxxxx +| +| | xxxxxxxxxxxxxxxx +| +| | xxxxxxxxxxxxxxxxxx +| +| | xxxxxxxxxxxxxxxxxxxx | +| a | yyyyyyyyyyyyyyyy +| +| | yyyyyyyyyyyyyy +| +| | yyyyyyyyyyyy +| +| | yyyyyyyyyy +| +| | yyyyyyyy +| +| | yyyyyy +| +| | yyyy +| +| | yy +| +| | | ++-------+------------------------------+ + +\pset linestyle old-ascii +\pset expanded off +\pset columns 40 +\pset border 0 +\pset format unaligned +execute q; +abcde|a +xx|yyyyyyyyyyyyyyyyyy +xxxx +xxxxxx +xxxxxxxx +xxxxxxxxxx +xxxxxxxxxxxx +xxxxxxxxxxxxxx +xxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxx|yyyyyyyyyyyyyyyy +yyyyyyyyyyyyyy +yyyyyyyyyyyy +yyyyyyyyyy +yyyyyyyy +yyyyyy +yyyy +yy + +(2 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 +(2 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 +(2 rows) + +\pset border 1 +\pset format unaligned +execute q; +abcde|a +xx|yyyyyyyyyyyyyyyyyy +xxxx +xxxxxx +xxxxxxxx +xxxxxxxxxx +xxxxxxxxxxxx +xxxxxxxxxxxxxx +xxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxx|yyyyyyyyyyyyyyyy +yyyyyyyyyyyyyy +yyyyyyyyyyyy +yyyyyyyyyy +yyyyyyyy +yyyyyy +yyyy +yy + +(2 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 : +(2 rows) + +\pset format wrapped +execute q; + abcde | a +-------------------+-------------------- + xx | yyyyyyyyyyyyyyyyyy + xxxx | yyyyyyyyyyyyyyyy + xxxxxx : yyyyyyyyyyyyyy + xxxxxxxx : yyyyyyyyyyyy + xxxxxxxxxx : yyyyyyyyyy + xxxxxxxxxxxx : yyyyyyyy + xxxxxxxxxxxxxx : yyyyyy + xxxxxxxxxxxxxxxx : yyyy + xxxxxxxxxxxxxxxxx : yy + x : + xxxxxxxxxxxxxxxxx + xxx +(2 rows) + +\pset border 2 +\pset format unaligned +execute q; +abcde|a +xx|yyyyyyyyyyyyyyyyyy +xxxx +xxxxxx +xxxxxxxx +xxxxxxxxxx +xxxxxxxxxxxx +xxxxxxxxxxxxxx +xxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxx|yyyyyyyyyyyyyyyy +yyyyyyyyyyyyyy +yyyyyyyyyyyy +yyyyyyyyyy +yyyyyyyy +yyyyyy +yyyy +yy + +(2 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 : | ++----------------------+--------------------+ +(2 rows) + +\pset format wrapped +execute q; ++-----------------+--------------------+ +| abcde | a | ++-----------------+--------------------+ +| xx | yyyyyyyyyyyyyyyyyy | +| xxxx | yyyyyyyyyyyyyyyy | +| xxxxxx : yyyyyyyyyyyyyy | +| xxxxxxxx : yyyyyyyyyyyy | +| xxxxxxxxxx : yyyyyyyyyy | +| xxxxxxxxxxxx : yyyyyyyy | +| xxxxxxxxxxxxxx : yyyyyy | +| xxxxxxxxxxxxxxx : yyyy | +| x : yy | +| xxxxxxxxxxxxxxx : | +| xxx | +| xxxxxxxxxxxxxxx | +| xxxxx | ++-----------------+--------------------+ +(2 rows) + +\pset expanded on +\pset border 0 +\pset format unaligned +execute q; +abcde|xx +a|yyyyyyyyyyyyyyyyyy + +abcde|xxxx +xxxxxx +xxxxxxxx +xxxxxxxxxx +xxxxxxxxxxxx +xxxxxxxxxxxxxx +xxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxx +a|yyyyyyyyyyyyyyyy +yyyyyyyyyyyyyy +yyyyyyyyyyyy +yyyyyyyyyy +yyyyyyyy +yyyyyy +yyyy +yy + +\pset format aligned +execute q; +* Record 1 +abcde xx +a yyyyyyyyyyyyyyyyyy +* Record 2 +abcde xxxx + xxxxxx + xxxxxxxx + xxxxxxxxxx + xxxxxxxxxxxx + xxxxxxxxxxxxxx + xxxxxxxxxxxxxxxx + xxxxxxxxxxxxxxxxxx + xxxxxxxxxxxxxxxxxxxx +a yyyyyyyyyyyyyyyy + yyyyyyyyyyyyyy + yyyyyyyyyyyy + yyyyyyyyyy + yyyyyyyy + yyyyyy + yyyy + yy + + +\pset format wrapped +execute q; +* Record 1 +abcde xx +a yyyyyyyyyyyyyyyyyy +* Record 2 +abcde xxxx + xxxxxx + xxxxxxxx + xxxxxxxxxx + xxxxxxxxxxxx + xxxxxxxxxxxxxx + xxxxxxxxxxxxxxxx + xxxxxxxxxxxxxxxxxx + xxxxxxxxxxxxxxxxxxxx +a yyyyyyyyyyyyyyyy + yyyyyyyyyyyyyy + yyyyyyyyyyyy + yyyyyyyyyy + yyyyyyyy + yyyyyy + yyyy + yy + + +\pset border 1 +\pset format unaligned +execute q; +abcde|xx +a|yyyyyyyyyyyyyyyyyy + +abcde|xxxx +xxxxxx +xxxxxxxx +xxxxxxxxxx +xxxxxxxxxxxx +xxxxxxxxxxxxxx +xxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxx +a|yyyyyyyyyyyyyyyy +yyyyyyyyyyyyyy +yyyyyyyyyyyy +yyyyyyyyyy +yyyyyyyy +yyyyyy +yyyy +yy + +\pset format aligned +execute q; +-[ RECORD 1 ]--------------- +abcde | xx +a | yyyyyyyyyyyyyyyyyy +-[ RECORD 2 ]--------------- +abcde | xxxx + : xxxxxx + : xxxxxxxx + : xxxxxxxxxx + : xxxxxxxxxxxx + : xxxxxxxxxxxxxx + : xxxxxxxxxxxxxxxx + : xxxxxxxxxxxxxxxxxx + : xxxxxxxxxxxxxxxxxxxx +a | yyyyyyyyyyyyyyyy + : yyyyyyyyyyyyyy + : yyyyyyyyyyyy + : yyyyyyyyyy + : yyyyyyyy + : yyyyyy + : yyyy + : yy + : + +\pset format wrapped +execute q; +-[ RECORD 1 ]--------------------------- +abcde | xx +a | yyyyyyyyyyyyyyyyyy +-[ RECORD 2 ]--------------------------- +abcde | xxxx + : xxxxxx + : xxxxxxxx + : xxxxxxxxxx + : xxxxxxxxxxxx + : xxxxxxxxxxxxxx + : xxxxxxxxxxxxxxxx + : xxxxxxxxxxxxxxxxxx + : xxxxxxxxxxxxxxxxxxxx +a | yyyyyyyyyyyyyyyy + : yyyyyyyyyyyyyy + : yyyyyyyyyyyy + : yyyyyyyyyy + : yyyyyyyy + : yyyyyy + : yyyy + : yy + : + +\pset border 2 +\pset format unaligned +execute q; +abcde|xx +a|yyyyyyyyyyyyyyyyyy + +abcde|xxxx +xxxxxx +xxxxxxxx +xxxxxxxxxx +xxxxxxxxxxxx +xxxxxxxxxxxxxx +xxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxx +a|yyyyyyyyyyyyyyyy +yyyyyyyyyyyyyy +yyyyyyyyyyyy +yyyyyyyyyy +yyyyyyyy +yyyyyy +yyyy +yy + +\pset format aligned +execute q; ++-[ RECORD 1 ]-----------------+ +| abcde | xx | +| a | yyyyyyyyyyyyyyyyyy | ++-[ RECORD 2 ]-----------------+ +| abcde | xxxx | +| : xxxxxx | +| : xxxxxxxx | +| : xxxxxxxxxx | +| : xxxxxxxxxxxx | +| : xxxxxxxxxxxxxx | +| : xxxxxxxxxxxxxxxx | +| : xxxxxxxxxxxxxxxxxx | +| : xxxxxxxxxxxxxxxxxxxx | +| a | yyyyyyyyyyyyyyyy | +| : yyyyyyyyyyyyyy | +| : yyyyyyyyyyyy | +| : yyyyyyyyyy | +| : yyyyyyyy | +| : yyyyyy | +| : yyyy | +| : yy | +| : | ++-------+----------------------+ + +\pset format wrapped +execute q; ++-[ RECORD 1 ]-------------------------+ +| abcde | xx | +| a | yyyyyyyyyyyyyyyyyy | ++-[ RECORD 2 ]-------------------------+ +| abcde | xxxx | +| : xxxxxx | +| : xxxxxxxx | +| : xxxxxxxxxx | +| : xxxxxxxxxxxx | +| : xxxxxxxxxxxxxx | +| : xxxxxxxxxxxxxxxx | +| : xxxxxxxxxxxxxxxxxx | +| : xxxxxxxxxxxxxxxxxxxx | +| a | yyyyyyyyyyyyyyyy | +| : yyyyyyyyyyyyyy | +| : yyyyyyyyyyyy | +| : yyyyyyyyyy | +| : yyyyyyyy | +| : yyyyyy | +| : yyyy | +| : yy | +| : | ++-------+------------------------------+ + +deallocate q; diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql index a7d5eeb..2cd6c55 100644 --- a/src/test/regress/sql/psql.sql +++ b/src/test/regress/sql/psql.sql @@ -160,3 +160,120 @@ execute q; execute q; deallocate q; + +-- test single-line headers, wrapping, and newline indicators +prepare q as select array_to_string(array_agg(repeat('x',2*n)),E'\n') as "abcde", +array_to_string(array_agg(repeat('y',20-2*n)),E'\n') as "a" +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; +\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; + +\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;