2017-03-17 48 views
1

當我有一個非常寬的列(如json文檔),我使用擴展顯示來使內容至少部分可讀時,我仍然看到非常醜陋的記錄分隔符,似乎想要要像最寬的列一樣寬,像這樣:psql擴展顯示 - 避免破折號

有沒有辦法避免「Dashes之海」?

- [RECORD 1] - + ------------------------------------ -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------------------------------------------

id | 18

description | {json數據xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}

參數| {json data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}

name | Foo

- [RECORD 2] - + ------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- --------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------------------------------------

id | 19

description | {}

參數| {json data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}

name | CustomerRequestEventType

回答

1

避免短線的海,使用\pset format unaligned,如:

t=# \x 
Expanded display is on. 
t=# \pset format unaligned 
Output format is unaligned. 
t=# with ts as (select generate_series('2010-01-01'::timestamp,'2010-01-10'::timestamp,'1 day'::interval) s) select array_agg(s) from ts;     array_agg|{"2010-01-01 00:00:00","2010-01-02 00:00:00","2010-01-03 00:00:00","2010-01-04 00:00:00","2010-01-05 00:00:00","2010-01-06 00:00:00","2010-01-07 00:00:00","2010-01-08 00:00:00","2010-01-09 00:00:00","2010-01-10 00:00:00"} 
Time: 0.250 ms 

正如你所看到的,沒有劃線,但長字符串仍是由窗口的長度裹滿線(或根本不包裹)。在沒有格式化的字符串的情況下,這是解決方案,但是您提到了json - 它可以用一種很漂亮的方式進行分類。要做到如此,而不是使用PSQL未對齊格式,消耗jsonb_pretty功能或其他功能pretty標誌,如(含array_to_json(..., true)

t=# with ts as (select generate_series('2010-01-01'::timestamp,'2010-01-31'::timestamp,'1 day'::interval) s) select array_to_json(array_agg(s),true) from ts; 
array_to_json|["2010-01-01T00:00:00", 
"2010-01-02T00:00:00", 
"2010-01-03T00:00:00", 
"2010-01-04T00:00:00", 
"2010-01-05T00:00:00", 
"2010-01-06T00:00:00", 
"2010-01-07T00:00:00", 
"2010-01-08T00:00:00", 
"2010-01-09T00:00:00", 
"2010-01-10T00:00:00", 
"2010-01-11T00:00:00", 
"2010-01-12T00:00:00", 
"2010-01-13T00:00:00", 
"2010-01-14T00:00:00", 
"2010-01-15T00:00:00", 
"2010-01-16T00:00:00", 
"2010-01-17T00:00:00", 
"2010-01-18T00:00:00", 
"2010-01-19T00:00:00", 
"2010-01-20T00:00:00", 
"2010-01-21T00:00:00", 
"2010-01-22T00:00:00", 
"2010-01-23T00:00:00", 
"2010-01-24T00:00:00", 
"2010-01-25T00:00:00", 
"2010-01-26T00:00:00", 
"2010-01-27T00:00:00", 
"2010-01-28T00:00:00", 
"2010-01-29T00:00:00", 
"2010-01-30T00:00:00", 
"2010-01-31T00:00:00"] 
Time: 0.291 ms 

注意我仍然可以使用未對齊格式,以避免出現「+」雖然...