Does anyone know if Postgres has a way to display query results "prettily", like how MySQL does when ending a query with \G on the command line? For instance, "select * from sometable\G" as opposed to "select * from sometable;"
Many thanks!
Does anyone know if Postgres has a way to display query results "prettily", like how MySQL does when ending a query with \G on the command line? For instance, "select * from sometable\G" as opposed to "select * from sometable;"
Many thanks!
I'm not familiar enough with MySQL to know what the \G option does, but based on the documentation it looks like the psql \x option might do what you want.
It's a toggle, though, so you do it before you submit the query.
Actually, you can enable \G mysql style formatting on a per-query basis in psql by putting the following in ~/.psqlrc:
You can then use :G at the end of a query in the psql client the same as you would \G at the end of a query in the mysql client:
Borrowing from this answer:
You can append
\x\g\x
to the query just as you would with MySQL's\G
. For example:Note the lack of
;
in the above line, this is intentional.This has the effect of enabling expanded display, running the expressed query, and disabling expanded display, all in one statement.
Since PostgreSQL 10,
psql
has\gx
which is the exact equivalent of mysql's\G
Documentation:
The sequence
\x\g\x
does the same, but only when\x
(=expanded display) is off. Otherwise it does the opposite! By contrast\gx
always displays with the expanded output independently of the current regime of\x
.You can toggle psql into extended mode with \x before you run a command, but you can't do it on a command by command basis like you can in mysql.