postgresql 在 psql 中垂直显示选择结果,就像 MySQL 的 \G 所做的那样

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22407860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 00:39:03  来源:igfitidea点击:

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

postgresqlpsql

提问by Drew Noakes

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

在 MySQL 中,您可以select使用\G(而不是\g)终止查询以垂直显示结果:

select * from foo \G

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

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

如何使用 psql 为 PostgreSQL 做同样的事情?

回答by Drew Noakes

You can do this by enabling Expanded display.

您可以通过启用Expanded display来做到这一点。

Toggle this setting via \x. For example:

通过 切换此设置\x。例如:

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

您可以通过使用\x\g\x后缀来打开扩展显示,运行查询,然后再次关闭它,从而为单个命令运行此命令。

select * from foo \x\g\x