Pregunta

Almost every psql query comes out an illegible mess if not preceded by display configuration commands such as \x auto. Typing this manually for each psql instance is annoying.

Expanded display is used automatically.

Is there any way to configure a better default display? Or perhaps the answer is to use a more advanced interactive terminal?

¿Fue útil?

Solución

Use .psqlrc to set defaults.

For the specific case of \x, newer psql versions (9.3, I think, but it might just be the 9.4 pre-release) can automatically switch to expanded output mode when the rows are too wide to fit on a line. From \?:

\x [on|off|auto] toggle expanded output (currently off)

So I suggest putting \x auto in your .psqlrc, rather than forcing it to on.

Otros consejos

It should also be noted that the psql command line option -x or --expanded is the same as using \x from within.


psql command-line options:

-P expanded=auto
--pset expanded=auto
-x
--expanded

within the psql shell:

\x

There is an option of -x but it does not do the job for me as I am using COPY to send output to a file. Without copy "-x" works well!

So here is what I have done to read:

# psql -U postgres -o /tmp/output_file_name.txt <<EOF
\x
SELECT * FROM pg_stat_activity;
EOF

Expanded display is on.

One can morph the above to whatever he/she needs to do. One can also do the same with an input file.

For me I add -q to turn that off for my psql command e.g.

psql postgresql://u:p@h:5432/db  -q            -c 'select 1'
#    connection string           turn it off   query
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top