Hi. Psql definitely have a problem with displaying "wide" tables. Even in expanded mode, they look horrible. So I tried to solve this problem.
Before the patch: postgres=# \x 1 Expanded display (expanded) is on. postgres=# \pset border 2 Border style (border) is 2. postgres=# select * from pg_stats; +-[ RECORD 1 ]-----------+------------------------------------------------------ -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ----------------------------------------------------------+ | schemaname | pg_catalog | | tablename | pg_proc ... and after: +-[ RECORD 1 ]-----------+-----------------------------------------------------+ | schemaname | pg_catalog | | tablename | pg_proc | | attname | proname | | inherited | f | | null_frac | 0 | | avg_width | 64 | | n_distinct | -0.823159 | | most_common_vals | {max,min,overlaps,has_column_privilege,date_part,int4 ,length,substring,sum,to_char,avg,int8,numeric,abs,generate_series,has_any_colum n_privilege,has_database_privilege,has_foreign_data_wrapper_privilege,has_functi on_privilege,has_language_privilege,has_schema_privilege,has_sequence_privilege, has_server_privilege,has_table_privilege,has_tablespace_privilege,has_type_privi lege,overlay,pg_has_role,point,stddev,stddev_pop,stddev_samp,text,time,timestamp tz,timezone,var_pop,var_samp,variance,age,float4,float8,int2,isfinite,pg_get_vie wdef,timestamp,bit_and,bit_or,mod,octet_length,polygon,substr,trunc,ts_headline, ts_rank,ts_rank_cd,area,bit,bit_length,box,bpchar,btrim,circle,date,date_trunc,i nterval,ishorizontal,isvertical,lag,lead,like,log,money,name,notlike,position,ro und,timetz,to_ascii,abbrev,abstime,array_fill,array_to_json,array_to_string,ceil ,ceiling,center,char,char_length,character_length,count,daterange,enum_range,exp ,floor,format,generate_subscripts,get_bit,gin_extract_tsquery,gin_extract_tsvect or} | ... | correlation | 0.254019 | | most_common_elems | | | most_common_elem_freqs | | | elem_count_histogram | | +-[ RECORD 2 ]-----------+-----------------------------------------------------+ | schemaname | pg_catalog | | tablename | pg_proc | | attname | pronamespace | | inherited | f | | null_frac | 0 | | avg_width | 4 | | n_distinct | 2 | | most_common_vals | {11,12410} | | most_common_freqs | {0.995274,0.00472627} | | histogram_bounds | | | correlation | 1 | | most_common_elems | | | most_common_elem_freqs | | | elem_count_histogram | | +-[ RECORD 3 ]-----------+-----------------------------------------------------+ Best regards, Sergey Muraviov
From 72cd7ec1d52b1d49e2f910d2677e331ea3088046 Mon Sep 17 00:00:00 2001 From: Sergey Muraviov <sergey.k.murav...@gmail.com> Date: Sun, 1 Dec 2013 14:18:11 +0400 Subject: [PATCH] print_aligned_vertical function has been fixed --- src/bin/psql/print.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index 736225c..f788928 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -1234,6 +1234,17 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) fprintf(fout, "%s\n", cont->title); } +#ifdef TIOCGWINSZ + int max_dwidth = 0; + struct winsize screen_size; + ioctl(fileno(stdout), TIOCGWINSZ, &screen_size); + max_dwidth = screen_size.ws_col - hwidth; + if (opt_border > 0) + max_dwidth -= ((opt_border == 2) ? 7: 3); /* +--+--+ : -+- */ + + if (dwidth > max_dwidth) + dwidth = max_dwidth; +#endif /* print records */ for (i = 0, ptr = cont->cells; *ptr; i++, ptr++) { @@ -1294,6 +1305,15 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout) if (!dcomplete) { +#ifdef TIOCGWINSZ + if (dlineptr[line_count].width > dwidth) + { + if (opt_border == 2) + dlineptr[line_count].width = dwidth - 2 + screen_size.ws_col - (dlineptr[line_count].width - dwidth - 2) % screen_size.ws_col; + else + dlineptr[line_count].width = dwidth; + } +#endif if (opt_border < 2) fprintf(fout, "%s\n", dlineptr[line_count].ptr); else -- 1.8.3.1
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers