本文介绍了为什么cqlsh右对齐字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现使用cqlsh显示的字符串值是右对齐的。有什么原因吗?有没有办法左对齐字符串?

I find that string-values displayed using cqlsh are right-aligned. Is there a reason for this? And is there a way to left-align strings?

cqlsh:test> create table test (id int, a ascii, t text, primary key(id));
cqlsh:test> insert into test (id, a, t) values (1, 'ascii', 'text');
cqlsh:test> insert into test (id, a, t) values (2, 'a', 't');       
cqlsh:test> select * from test;                              

 id | a     | t
----+-------+------
  1 | ascii | text
  2 |     a |    t

(2 rows)


推荐答案

我认为这主要是出于审美原因,但你可以改变它!

I think this is mostly done for aesthetic reasons, however you can change it!

cqlsh只是一个使用python驱动程序的python文件。您可以简单地更改cqlsh的 print_formatted_result 方法中的以下代码:

cqlsh is simply a python file that uses the python-driver. You can simply change the following code in the print_formatted_result method of cqlsh:

    for row in formatted_values:                                                
        line = ' | '.join(col.rjust(w, color=self.color) for (col, w) in zip(row, widths))
        self.writeresult(' ' + line)

您可以将col.rjust更改为ljust,center等,或者可以简单地将其更改为col以打印数据是

You can change col.rjust to ljust, center, etc. or you can simply change it to 'col' to print the data as is.

使用ljust的示例:

Example using ljust:

cqlsh:friends> select * from group_friends;

 groupid                              | friendid | time
--------------------------------------+----------+--------
 13814000-1dd2-11b2-8080-808080808080 | 1        | 123456
 13814000-1dd2-11b2-8080-808080808080 | 2        | 123456
 13814000-1dd2-11b2-8080-808080808080 | 4        | 123456
 13814000-1dd2-11b2-8080-808080808080 | 8        | 123456
 13814000-1dd2-11b2-8080-808080808080 | 22       | 123456
 13814000-1dd2-11b2-8080-808080808080 | 1002     | 123456

这篇关于为什么cqlsh右对齐字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 22:57