Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
up vote 53 down vote accepted

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.

select * from sometable;
share|improve this answer

Actually, you can enable \G mysql style formatting on a per-query basis in psql by putting the following in ~/.psqlrc:

\set G '\\set QUIET 1\\x\\g\\x\\set QUIET 0'

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:

pagila=# select * from foo limit 1;
 id | uniq | val |       val_ts        
  1 |    1 |   3 | 2007-07-03 00:00:00
(1 row)

Time: 11.481 ms
pagila=# select * from foo limit 1 :G
-[ RECORD 1 ]---------------
id     | 1
uniq   | 1
val    | 3
val_ts | 2007-07-03 00:00:00
share|improve this answer

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.

share|improve this answer

Borrowing from this answer:

You can append \x\g\x to the query just as you would with MySQL's \G. For example:

select * from users \x\g\x

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.