Disable wrapping in Psql output

后端 未结 5 1461
猫巷女王i
猫巷女王i 2021-02-06 21:43

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 s

相关标签:
5条回答
  • 2021-02-06 22:19

    To disable the wrapped output of the select query.

    \pset pager on and \pset pager off to switch back to the older output view.

    0 讨论(0)
  • 2021-02-06 22:20

    probably you should use aligned format for output:

    \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

    0 讨论(0)
  • 2021-02-06 22:20

    The default pager for psql is less. Then for no wrapped lines must be use less -S. PAGER="less -S" psql is a good aproach. But inside psql you can use

    \setenv PAGER 'less -S'
    
    0 讨论(0)
  • 2021-02-06 22:21

    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.

    Running psql to use less with the -S or --chop-long-lines option seemed to work for me:

    PAGER="less -S" psql
    

    You can also enable this feature while viewing output in less by typing -S and Enter.

    0 讨论(0)
  • 2021-02-06 22:22

    less's -F or -S flag will causes \d some_table to not show any output in some cases.

    -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.

    0 讨论(0)
提交回复
热议问题