Hi.
I've improved the patch.
It works in expanded mode when either format option is set to wrapped (\pset format wrapped), or we have no pager, or pager doesn't chop long lines (so you can still use the trick).
Target output width is taken from either columns option (\pset columns 70), or environment variable $COLUMNS, or terminal size.
And it's also compatible with any border style (\pset border 0|1|2).
Here are some examples:
postgres=# \x 1
postgres=# \pset format wrapped
postgres=# \pset border 0
postgres=# select * from wide_table;
* Record 1
value afadsafasd fasdf asdfasd fsad fas df sadf sad f sadf sadf sa df sadfsadfa
sd fsad fsa df sadf asd fa sfd sadfsadf asdf sad f sadf sad fadsf
* Record 2
value afadsafasd fasdf asdfasd
postgres=# \pset border 1
postgres=# \pset columns 70
postgres=# select * from wide_table;
-[ RECORD 1 ]---------------------------------------------------------
value | afadsafasd fasdf asdfasd fsad fas df sadf sad f sadf sadf sa
| df sadfsadfasd fsad fsa df sadf asd fa sfd sadfsadf asdf sad f
| sadf sad fadsf
-[ RECORD 2 ]---------------------------------------------------------
value | afadsafasd fasdf asdfasd
postgres=# \pset border 2
postgres=# \pset columns 60
postgres=# select * from wide_table;
+-[ RECORD 1 ]---------------------------------------------+
| value | afadsafasd fasdf asdfasd fsad fas df sadf sad f |
| | sadf sadf sa df sadfsadfasd fsad fsa df sadf as |
| | d fa sfd sadfsadf asdf sad f sadf sad fadsf |
+-[ RECORD 2 ]---------------------------------------------+
| value | afadsafasd fasdf asdfasd |
+-------+--------------------------------------------------+
Regards,
Sergey