Cassandra并不像mysql一样几乎支持几乎所有的类型间转换,下面是一个支持转换的列表
ascii -> blob, text, varchar
bigint -> blob, timestamp, varint
int -> blob, varint
text -> blob, varchar
timestamp -> bigint, blob, varint
timeuuid -> blob, UUID
varchar -> blob, text
注意:
几乎所有类型都可以转换到blob
cqlsh 允许 varint 转换为 date,但是这是bug,不要尝试
alter table user alter user_name type blob;
如果你想曲线救国
我先drop 再 add 这个字段,不行
你会看到提示
这是一个bug
https://issues.apache.org/jira/browse/CASSANDRA-9816
最新版本可以试试是否已经修复
2016年6月1日更新
3.0 alpha 1 说已经修复,下面是测试结果:
kevin@cqlsh:test> alter table user drop user_name;
kevin@cqlsh:test> alter table user add user_name int;
kevin@cqlsh:test> select * from user;
uid | user_name
-----+-----------
(0 rows)
kevin@cqlsh:test> insert into user(uid,user_name) values(1,'kevin');
InvalidRequest: code=2200 [Invalid query] message="Invalid STRING constant (kevin) for "user_name" of type int"
kevin@cqlsh:test> insert into user(uid,user_name) values(1,233);
kevin@cqlsh:test> select * from user;
uid | user_name
-----+-----------
1 | 233
(1 rows)
kevin@cqlsh:test> alter table user drop user_name;
kevin@cqlsh:test> alter table user add user_name text;
kevin@cqlsh:test> insert into user(uid,user_name) values(1,'kevin');
kevin@cqlsh:test> select * from user;
uid | user_name
-----+-----------
1 | kevin
(1 rows)
现在,你可以曲线救国了。。。