Alternate output format for psql

前端 未结 7 1848
迷失自我
迷失自我 2020-12-04 04:44

I am using PostgreSQL 8.4 on Ubuntu. I have a table with columns c1 through cN. The columns are wide enough that selecting all columns causes a row

7条回答
  •  温柔的废话
    2020-12-04 04:54

    (New) Expanded Auto Mode: \x auto

    New for Postgresql 9.2; PSQL automatically fits records to the width of the screen. previously you only had expanded mode on or off and had to switch between the modes as necessary.

    • If the record can fit into the width of the screen; psql uses normal formatting.
    • If the record can not fit into the width of the screen; psql uses expanded mode.

    To get this use: \x auto

    Postgresql 9.5 Documentation on PSQL command.


    Wide screen, normal formatting:

     id | time  |       humanize_time             | value 
    ----+-------+---------------------------------+-------
      1 | 09:30 |  Early Morning - (9.30 am)      |   570
      2 | 11:30 |  Late Morning - (11.30 am)      |   690
      3 | 13:30 |  Early Afternoon - (1.30pm)     |   810
      4 | 15:30 |  Late Afternoon - (3.30 pm)     |   930
    (4 rows)
    

    Narrow screen, expanded formatting:

    -[ RECORD 1 ]-+---------------------------
    id            | 1
    time          | 09:30
    humanize_time | Early Morning - (9.30 am)
    value         | 570
    -[ RECORD 2 ]-+---------------------------
    id            | 2
    time          | 11:30
    humanize_time | Late Morning - (11.30 am)
    value         | 690
    -[ RECORD 3 ]-+---------------------------
    id            | 3
    time          | 13:30
    humanize_time | Early Afternoon - (1.30pm)
    value         | 810
    -[ RECORD 4 ]-+---------------------------
    id            | 4
    time          | 15:30
    humanize_time | Late Afternoon - (3.30 pm)
    value         | 930
    

    How to start psql with \x auto?

    Configure \x auto command on startup by adding it to .psqlrc in your home folder and restarting psql. Look under 'Files' section in the psql doc for more info.

    ~/.psqlrc

    \x auto
    

提交回复
热议问题