Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

postgresql - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 xgx suffix to toggle expanded display on, run the query, then toggle it off again.

select * from foo xgx

Or via psql param as shared here

psql db -xc 'select * from table'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...