cqlsh:在UDT中插入一个值

时间:2016-05-19 05:53:03

标签: cassandra datastax cassandra-2.0 cqlsh

我创建了一个UDT -

CREATE TYPE home.my_object (
   id text,
   type text,
   quantity int,
   critical boolean,
   count int,
   stock text,
   envelope boolean
  );

 ALTER TABLE home.product ADD my_objects list<frozen<my_object>>;

我编写了一个脚本并尝试对数据库运行以执行插入/更新但收到错误消息

这是我的脚本 -

       Update home.product set my_objects[''] = {
         id: '3.MYFIT-LTR-DYN',
         type: 'COMPONENT',
         quantity: null,
         critical: '',
         count: null,
         stock:'',
         envelope:''
     }  where id = 'FIT-GI';

执行此语句时,我遇到错误 -

      code=2200 [Invalid query] message="Invalid STRING constant () for "idx(my_objects)" of type int"

1 个答案:

答案 0 :(得分:1)

关键字和包络的DataType是布尔值,因此您必须将值用作True / False

如果要更新列表中的特定索引,则查询将为:

 Update home.product set my_objects[0] = {
         id: '3.MYFIT-LTR-DYN',
         type: 'COMPONENT',
         quantity: null,
         critical: true,
         count: null,
         stock:'',
         envelope:true
     }  where id = 'FIT-GI';

注意:将0替换为您想要的索引

如果要将值添加到现有列表,则查询将为:

 Update home.product set my_objects = my_objects + [{
         id: '3.MYFIT-LTR-DYN',
         type: 'COMPONENT',
         quantity: null,
         critical: true,
         count: null,
         stock:'',
         envelope:true
     }]  where id = 'FIT-GI';

如果您想完全替换my_objects的值,那么:

 Update home.product set my_objects = [{
         id: '3.MYFIT-LTR-DYN',
         type: 'COMPONENT',
         quantity: null,
         critical: true,
         count: null,
         stock:'',
         envelope:true
     }]  where id = 'FIT-GI';