bash 禁用 Psql 输出中的换行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39850860/
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
Disable wrapping in Psql output
提问by Silveri
When using Psql in Linux, if the result of my SQL query contains many columns or long strings of data, it will wrap the initial view and only once I scroll to the side will it stop wrapping and show each row on a separate line.
在 Linux 中使用 Psql 时,如果我的 SQL 查询的结果包含许多列或长数据字符串,它将包装初始视图,只有当我滚动到一边时,它才会停止包装并将每一行显示在单独的行上。
I've tried various \pset
optionssuch as format unaligned
, format aligned
, format wrapped
, columns 0
, columns 1000
, but none seemed to fullystop wrapping unless I generate static output to a file.
我尝试了各种\pset
选项,例如format unaligned
, format aligned
, format wrapped
, columns 0
, columns 1000
,但似乎没有一个选项完全停止换行,除非我将静态输出生成到文件。
How can I set it to never wrap the output while still being scrollable and showing the result using the default ascii table format?
如何将其设置为从不包装输出,同时仍可滚动并使用默认的 ascii 表格式显示结果?
回答by Silveri
Psql
uses a system viewer to show its output in the console. In bash
it likely uses less
for the scrollable/page-able features it provides. To use a different viewer or use different settings, you just need to set the PAGER
environment variable.
Psql
使用系统查看器在控制台中显示其输出。在bash
很可能使用less
了它提供的滚动/页能功能。要使用不同的查看器或使用不同的设置,您只需要设置PAGER
环境变量。
Running psql
to use less
with the -S
or --chop-long-lines
option seemed to work for me:
运行与or选项psql
一起使用似乎对我有用:less
-S
--chop-long-lines
PAGER="less -S" psql
You can also enable this feature while viewing output in less
by typing -S
and Enter.
您还可以在less
通过键入-S
和查看输出时启用此功能Enter。
回答by Akshay Shet
To disable the wrapped output of the select query.
禁用选择查询的包装输出。
\pset pager onand \pset pager offto switch back to the older output view.
\pset pager on和 \pset pager off切换回旧的输出视图。
回答by Arian Daneshvar
less's -F
or -S
flag will causes \d some_table
to not show any output in some cases.
在某些情况下,less-F
或-S
flag 将导致\d some_table
不显示任何输出。
-F or --quit-if-one-screen
Causes less to automatically exit if the entire file can be
displayed on the first screen.
-S or --chop-long-lines
Causes lines longer than the screen width to be chopped rather than folded.
That is, the portion of a long line that does not fit in the screen width is
not shown. The default is to fold long lines; that is, display the remainder
on the next line.
Use them like this:
像这样使用它们:
PAGER="less -S" psql
Seems safer at the inconvenience of having to manually exit less.
减少手动退出带来的不便似乎更安全。
回答by Eugen Konkov
probably you should use aligned
format for output:
可能你应该使用aligned
格式输出:
\pset format aligned
You can check all available formats to fit your needs:
您可以检查所有可用格式以满足您的需求:
\pset format TAB
aligned html latex-longtable unaligned
asciidoc latex troff-ms wrapped
Also you should check PAGER
configured value in your environment
您还应该检查PAGER
环境中的配置值