cqlsh:在 UDT 中插入一个值
cqlsh: Inserting a value in UDT
我创建了一个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>>;
我写了一个脚本并尝试 运行 对数据库执行 insert/update 但收到错误消息
这是我的脚本-
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"
关键和信封的数据类型是布尔值,因此您必须使用值作为 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';
我创建了一个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>>;
我写了一个脚本并尝试 运行 对数据库执行 insert/update 但收到错误消息
这是我的脚本-
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"
关键和信封的数据类型是布尔值,因此您必须使用值作为 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';