Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 573
Drew Noakes Avatar asked Mar 14 '14 14:03

Drew Noakes


People also ask

Which command can be used in psql to show all the available?

The psql commands \df and \do can be used to list all available functions and operators, respectively.

What is the psql command for toggle timing of commands?

You can use \timing only with the command line client psql , since this is a psql command. It is a switch that turns execution time reporting on and off: test=> \timing Timing is on.


1 Answers

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' 
like image 95
Drew Noakes Avatar answered Sep 27 '22 23:09

Drew Noakes