Apart from csv
style mentioned in other answers, the default horiz
style combined with an appropriate value in colsep
(not bcp_colsep
) will produce separated-output with column names.
1> \set colsep="|"
1> select * from Table where Blah=Blah
2> go
|heading1|heading2|
|--------|--------|
|row1 |col2 |
|row2 |col2 |
However, column values are padded and both the heading-underline and an initial column-separator before the first column are also printed. These could be stripped-off with awk
, for example. Perhaps there is no panacea...
A tab character as column separator must be inserted literally with CtrlV-Tab unless a recent sqsh
is being used (information from this question: What options are there for the sqsh style "csv" (or anyway to get tab-delimited out)).