diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2015-12-01 14:47:13 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2015-12-01 14:47:13 -0500 |
commit | 95708e1d8e38bc1f7f6ee02c38dd86dd53b9663c (patch) | |
tree | b137d77eddbd11cca861700054d84acf154f1b8f /src/bin/psql/print.c | |
parent | db4a5cfc76206db82d0b929d96c53de229ef1aa4 (diff) | |
download | postgresql-95708e1d8e38bc1f7f6ee02c38dd86dd53b9663c.tar.gz postgresql-95708e1d8e38bc1f7f6ee02c38dd86dd53b9663c.zip |
Further tweaking of print_aligned_vertical().
Don't force the data width to extend all the way to the right margin if it
doesn't need to. This reverts the behavior in non-wrapping cases to be
what it was in 9.4. Also, make the logic that ensures the data line width
is at least equal to the record-header line width a little less obscure.
In passing, avoid possible calculation of log10(0). Probably that's
harmless, given the lack of field complaints, but it seems risky:
conversion of NaN to an integer isn't well defined.
Diffstat (limited to 'src/bin/psql/print.c')
-rw-r--r-- | src/bin/psql/print.c | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index e103d5b0841..97f9c2f1690 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -1265,7 +1265,7 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) /* * Deal with the pager here instead of in printTable(), because we could * get here via print_aligned_text() in expanded auto mode, and so we have - * to recalcuate the pager requirement based on vertical output. + * to recalculate the pager requirement based on vertical output. */ IsPagerNeeded(cont, 0, true, &fout, &is_pager); @@ -1400,7 +1400,8 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) /* Determine width required for record header lines */ if (!opt_tuples_only) { - rwidth = 1 + log10(cont->nrows); + if (cont->nrows > 0) + rwidth = 1 + (int) log10(cont->nrows); if (opt_border == 0) rwidth += 9; /* "* RECORD " */ else if (opt_border == 1) @@ -1412,33 +1413,46 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) /* We might need to do the rest of the calculation twice */ for (;;) { - unsigned int width, - min_width; + unsigned int width; /* Total width required to not wrap data */ width = hwidth + swidth + dwidth; + /* ... and not the header lines, either */ + if (width < rwidth) + width = rwidth; - /* Minimum acceptable width: room for just 3 columns of data */ - min_width = hwidth + swidth + 3; - /* ... but not less than what the record header lines need */ - if (rwidth > min_width) - min_width = rwidth; - - if (width < min_width || - (output_columns > 0 && output_columns < min_width)) - { - /* Set data width to match min_width */ - newdwidth = min_width - hwidth - swidth; - } - else if (output_columns > 0) + if (output_columns > 0) { - /* Set data width to match output_columns */ - newdwidth = output_columns - hwidth - swidth; + unsigned int min_width; + + /* Minimum acceptable width: room for just 3 columns of data */ + min_width = hwidth + swidth + 3; + /* ... but not less than what the record header lines need */ + if (min_width < rwidth) + min_width = rwidth; + + if (output_columns >= width) + { + /* Plenty of room, use native data width */ + /* (but at least enough for the record header lines) */ + newdwidth = width - hwidth - swidth; + } + else if (output_columns < min_width) + { + /* Set data width to match min_width */ + newdwidth = min_width - hwidth - swidth; + } + else + { + /* Set data width to match output_columns */ + newdwidth = output_columns - hwidth - swidth; + } } else { - /* Use native data width */ - newdwidth = dwidth; + /* Don't know the wrap limit, so use native data width */ + /* (but at least enough for the record header lines) */ + newdwidth = width - hwidth - swidth; } /* |