Everyone using git diff in color mode will already or soon be aware that
psql, for what I can only think is an implementation oversight, produces
trailing whitespace in the table headers, like this:

 two |     f1     $
-----+------------$
     | asdfghjkl;$
     | d34aaasdf$
(2 rows)$

($ is the line end; cf. cat -A).  Note that this only applies to
headers, not content cells.

Attached is a patch to fix that.

diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index e55404b..da23b7b 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -817,20 +817,24 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
 						nbspace = width_wrap[i] - this_line->width;
 
 						/* centered */
-						fprintf(fout, "%-*s%s%-*s",
-								nbspace / 2, "", this_line->ptr, (nbspace + 1) / 2, "");
+						fprintf(fout, "%-*s%s",
+								nbspace / 2, "", this_line->ptr);
 
 						if (!(this_line + 1)->ptr)
 						{
 							more_col_wrapping--;
-							header_done[i] = 1;
+							header_done[i] = true;
 						}
+
+						if (i < cont->ncolumns - 1 || !header_done[i])
+							fprintf(fout, "%-*s",
+									(nbspace + 1) / 2, "");
 					}
 					else
 						fprintf(fout, "%*s", width_wrap[i], "");
 
 					if (opt_border != 0 || format->wrap_right_border == true)
-						fputs(!header_done[i] ? format->header_nl_right : " ",
+						fputs(!header_done[i] ? format->header_nl_right : (i < cont->ncolumns -1 ? " " : ""),
 							  fout);
 
 					if (opt_border != 0 && i < col_count - 1)
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to