【问题标题】:cqlsh: Inserting a value in UDTcqlsh:在 UDT 中插入一个值
【发布时间】:2016-09-15 20:11:41
【问题描述】:

我创建了一个 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"

【问题讨论】:

    标签: cassandra datastax cassandra-2.0 cqlsh


    【解决方案1】:

    关键和信封的数据类型是布尔值,因此您必须将值用作真/假

    如果您想更新列表中的特定索引,那么您的查询将是:

     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';
    

    【讨论】:

      猜你喜欢
      • 2016-09-15
      • 2018-02-27
      • 1970-01-01
      • 2023-03-23
      • 2015-08-03
      • 2021-06-08
      • 1970-01-01
      • 2013-09-19
      • 1970-01-01
      相关资源
      最近更新 更多