在Psql输出中禁用包装

问题描述 投票:23回答:4

在Linux中使用Psql时,如果我的SQL查询的结果包含许多列或长数据字符串,它将包装初始视图,只有当我滚动到侧面时它才会停止换行并在单独的行上显示每一行。

我尝试了各种\pset options,如format unalignedformat alignedformat wrappedcolumns 0columns 1000,但似乎没有一个完全停止包装,除非我生成静态输出到文件。

如何将其设置为永不包装输出,同时仍然可滚动并使用默认的ascii表格式显示结果?

bash postgresql psql
4个回答
40
投票

Psql使用系统查看器在控制台中显示其输出。在bash,它可能使用less来提供它的可滚动/可页面功能。要使用不同的查看器或使用不同的设置,您只需要设置PAGER环境变量。

运行psql使用less-S--chop-long-lines选项似乎对我有用:

PAGER="less -S" psql

您还可以通过键入less和Enter来查看-S中的输出时启用此功能。


10
投票

禁用select查询的包装输出。

\ pset pager on和\ pset pager off关闭以切换回旧的输出视图。


7
投票

较少的-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

由于不得不手动退出更不方便,似乎更安全。


2
投票

可能你应该使用aligned格式输出:

\pset format aligned

您可以检查所有可用格式以满足您的需求:

\pset format TAB
aligned          html             latex-longtable  unaligned        
asciidoc         latex            troff-ms         wrapped       

您还应该检查环境中的PAGER配置值

© www.soinside.com 2019 - 2024. All rights reserved.