在Linux中使用Psql时,如果我的SQL查询的结果包含许多列或长数据字符串,它将包装初始视图,只有当我滚动到侧面时它才会停止换行并在单独的行上显示每一行。
我尝试了各种\pset
options,如format unaligned
,format aligned
,format wrapped
,columns 0
,columns 1000
,但似乎没有一个完全停止包装,除非我生成静态输出到文件。
如何将其设置为永不包装输出,同时仍然可滚动并使用默认的ascii表格式显示结果?
Psql
使用系统查看器在控制台中显示其输出。在bash
,它可能使用less
来提供它的可滚动/可页面功能。要使用不同的查看器或使用不同的设置,您只需要设置PAGER
环境变量。
运行psql
使用less
与-S
或--chop-long-lines
选项似乎对我有用:
PAGER="less -S" psql
您还可以通过键入less
和Enter来查看-S
中的输出时启用此功能。
禁用select查询的包装输出。
\ pset pager on和\ pset pager off关闭以切换回旧的输出视图。
较少的-F
或-S
标志将导致\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.
像这样使用它们:
PAGER="less -S" psql
由于不得不手动退出更不方便,似乎更安全。
可能你应该使用aligned
格式输出:
\pset format aligned
您可以检查所有可用格式以满足您的需求:
\pset format TAB
aligned html latex-longtable unaligned
asciidoc latex troff-ms wrapped
您还应该检查环境中的PAGER
配置值