博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Cassandra 类型转换限制
阅读量:6872 次
发布时间:2019-06-26

本文共 1667 字,大约阅读时间需要 5 分钟。

原文地址:http://stackoverflow.com/questions/31880381/cassandra-alter-column-type-which-types-are-compatible

版本: Cassandra 2.2.0
2016年6月1日更新,版本3.0+

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 这个字段,不行

你会看到提示

InvalidRequest: code=2200 [Invalid query] message="Cannot add a collection with the name pics because a collection with the same name and a different type has already been used in the past"

这是一个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)

现在,你可以曲线救国了。。。

转载于:https://www.cnblogs.com/didda/p/5072393.html

你可能感兴趣的文章
JDK源码分析:Short.java
查看>>
黄聪:wordpress工作原理
查看>>
.NET上传大文件时提示Maximum request length exceeded错误的解决方法
查看>>
SQL 标量函数-----日期函数 day() 、month()、year()
查看>>
替换空格
查看>>
《Programming in Lua 3》读书笔记(二十二)
查看>>
ubuntu16.04中将python3设置为默认
查看>>
【使用Java原生API编写发送HTTP_POST请求的工具类】
查看>>
Leetcode2 Add Two Numbers
查看>>
R语言线性混合效应模型实战案例
查看>>
python27+selenium3自动化登录测试
查看>>
Effective C++ 之 0 导读(Introduction)
查看>>
Io Language Demo code first day
查看>>
C#动态调用webService出现 基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。...
查看>>
新闻发布项目——后台JSP界面adminManage/addNews.jsp
查看>>
常用的字符串加密解密工具类
查看>>
web渐进式应用PWA
查看>>
Eclipse快捷键大全(一)
查看>>
mybatis3温故
查看>>
Android 文件管理方法
查看>>