Display select results vertically in psql, as is done by MySQL's \G

PostgresqlPsql

Postgresql Problem Overview


In MySQL, you can terminate a select query with \G (as opposed to \g) to display the results vertically:

select * from foo \G

***************
 id: 1
bar: Hello
***************
 id: 2
bar: World

How can one do the same thing for PostgreSQL using psql?

Postgresql Solutions


Solution 1 - Postgresql

You can do this by enabling Expanded display.

Toggle this setting via \x. For example:

# \x
Expanded display is on.
# \x
Expanded display is off.

When on, results are shown in tabular (vertical) form:

-[ RECORD 1 ]
id  | 1
bar | Hello
-[ RECORD 2 ]
id  | 2
bar | World

You can run this for a single command by using the \x\g\x suffix to toggle expanded display on, run the query, then toggle it off again.

select * from foo \x\g\x

Or via psql param as shared here

psql db -xc 'select * from table'

Solution 2 - Postgresql

Same can be achieved in dbeaver for postgres using "record" option in grid results

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDrew NoakesView Question on Stackoverflow
Solution 1 - PostgresqlDrew NoakesView Answer on Stackoverflow
Solution 2 - PostgresqlitsavyView Answer on Stackoverflow