Alternate output format for psql

user100464 picture user100464 · Mar 7, 2012 · Viewed 210.6k times · Source

I am using PostgreSQL 8.4 on Ubuntu. I have a table with columns c1 through cN. The columns are wide enough that selecting all columns causes a row of query results to wrap multiple times. Consequently, the output is hard to read.

When the query results constitute just a few rows, it would be convenient if I could view the query results such that each column of each row is on a separate line, e.g.

 c1: <value of row 1's c1>
 c2: <value of row 1's c1>
 ...
 cN: <value of row 1's cN>
 ---- some kind of delimiter ----
 c1: <value of row 2's c1>
 etc.

I am running these queries on a server where I would prefer not to install any additional software. Is there a psql setting that will let me do something like that?

Answer

user100464 picture user100464 · Mar 7, 2012

I just needed to spend more time staring at the documentation. This command:

\x on

will do exactly what I wanted. Here is some sample output:

select * from dda where u_id=24 and dda_is_deleted='f';
-[ RECORD 1 ]------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
dda_id             | 1121
u_id               | 24
ab_id              | 10304
dda_type           | CHECKING
dda_status         | PENDING_VERIFICATION
dda_is_deleted     | f
dda_verify_op_id   | 44938
version            | 2
created            | 2012-03-06 21:37:50.585845
modified           | 2012-03-06 21:37:50.593425
c_id               | 
dda_nickname       | 
dda_account_name   | 
cu_id              | 1
abd_id             |