Sil*_*eri 28 postgresql bash psql
在Linux中使用Psql时,如果我的SQL查询的结果包含许多列或长数据字符串,它将包装初始视图,只有当我滚动到侧面时它才会停止换行并在单独的行上显示每一行.
我已经尝试了各种\pset方案,如format unaligned,format aligned,format wrapped,columns 0,columns 1000,但似乎没有一个完全停止包装,除非我生成静态输出到文件.
如何将其设置为永不包装输出,同时仍然可滚动并使用默认的ascii表格式显示结果?
Sil*_*eri 45
Psql使用系统查看器在控制台中显示其输出.在bash很可能使用less了它提供的滚动/页能功能.要使用其他查看器或使用不同的设置,只需设置PAGER环境变量即可.
运行psql使用less与-S或--chop-long-lines选项似乎为我工作:
PAGER="less -S" psql
Run Code Online (Sandbox Code Playgroud)
您还可以less通过键入-S和查看输出来启用此功能Enter.
Ale*_*elo 18
默认寻呼机psql是less。然后,对于没有换行的情况,必须使用less -S.
PAGER="less -S" psql是一个很好的方法。但在里面 psql你可以使用
\setenv PAGER 'less -S'
Run Code Online (Sandbox Code Playgroud)
然后,要将其关闭并重新打开,请使用
\pset pager off
\pset pager on
Run Code Online (Sandbox Code Playgroud)
小智 8
less -F或-Sflag将导致\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.
Run Code Online (Sandbox Code Playgroud)
像这样使用它们:
PAGER="less -S" psql
Run Code Online (Sandbox Code Playgroud)
由于不得不手动退出更不方便,似乎更安全.
可能您应该使用alignedformat进行输出:
\pset format aligned
Run Code Online (Sandbox Code Playgroud)
您可以检查所有可用格式以满足您的需求:
\pset format TAB
aligned html latex-longtable unaligned
asciidoc latex troff-ms wrapped
Run Code Online (Sandbox Code Playgroud)
另外,您还应该检查PAGER环境中的配置值
| 归档时间: |
|
| 查看次数: |
9714 次 |
| 最近记录: |