zoukankan      html  css  js  c++  java
  • Cassandra 类型转换限制

    原文地址: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)
    

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

  • 相关阅读:
    socket.io
    CUDA升级后
    QT安装
    windows时钟服务设置
    QT的DPI支持
    cudaDeviceProp结构体
    C#调用C++的dll各种传参
    「LibreOJ#516」DP 一般看规律
    「LibreOJ#515」贪心只能过样例 (暴力+bitset)
    [Codeforces888E]Maximum Subsequence(暴力+meet-in-the-middle)
  • 原文地址:https://www.cnblogs.com/didda/p/5072393.html
Copyright © 2011-2022 走看看