在地图中编辑用户类型
Editing a user type inside a map
我有这个table和用户类型
CREATE TYPE IF NOT EXISTS criteria (
id text,
enumerate text,
name text,
description text,
);
CREATE TYPE IF NOT EXISTS module (
id text,
enumerate text,
name text,
description text,
criteria map<int, frozen<criteria>>
);
CREATE TABLE IF NOT EXISTS certification (
id timeuuid,
owner text,
description text,
name text,
template map<int, frozen<module>>,
images map<text, text>,
PRIMARY KEY (id, owner)
);
如何使用条件在地图中更新或添加新数据。
先在模板字段中添加数据
UPDATE certification set template = template +
{1:{
id: '***',
enumerate: '***',
name: 'aaa',
description: 'aaa',
criteria: {}
}}
where owner='***' and id = ***;
之后,我想更新条件。我正在尝试这个(认证 table 已经有数据并且模板字段有映射键 = 1 ):
UPDATE certification set
template[1].criteria = template[1].criteria +
{1:{
id: 'xxxx',
enumerate: 'xxxx',
name: 'xxxx',
description: 'xxxx'
}}
where owner='****' and id = ***;
或template[1]['criteria']
但是我得到一个错误。
SyntaxException: line 2:27 mismatched input '.' expecting '='
字段模板值定义为frozen,frozen是不可变的
你不能更新冻结的项目,你必须重新插入完整的价值。
A frozen value serializes multiple components into a single value. Non-frozen types allow updates to individual fields. Cassandra treats the value of a frozen type as a blob. The entire value must be overwritten.
此外,Cassandra 不支持集合中的非冻结字段
来源:https://docs.datastax.com/en/cql/3.1/cql/cql_reference/collection_type_r.html
我有这个table和用户类型
CREATE TYPE IF NOT EXISTS criteria (
id text,
enumerate text,
name text,
description text,
);
CREATE TYPE IF NOT EXISTS module (
id text,
enumerate text,
name text,
description text,
criteria map<int, frozen<criteria>>
);
CREATE TABLE IF NOT EXISTS certification (
id timeuuid,
owner text,
description text,
name text,
template map<int, frozen<module>>,
images map<text, text>,
PRIMARY KEY (id, owner)
);
如何使用条件在地图中更新或添加新数据。
先在模板字段中添加数据
UPDATE certification set template = template +
{1:{
id: '***',
enumerate: '***',
name: 'aaa',
description: 'aaa',
criteria: {}
}}
where owner='***' and id = ***;
之后,我想更新条件。我正在尝试这个(认证 table 已经有数据并且模板字段有映射键 = 1 ):
UPDATE certification set
template[1].criteria = template[1].criteria +
{1:{
id: 'xxxx',
enumerate: 'xxxx',
name: 'xxxx',
description: 'xxxx'
}}
where owner='****' and id = ***;
或template[1]['criteria']
但是我得到一个错误。
SyntaxException: line 2:27 mismatched input '.' expecting '='
字段模板值定义为frozen,frozen是不可变的
你不能更新冻结的项目,你必须重新插入完整的价值。
A frozen value serializes multiple components into a single value. Non-frozen types allow updates to individual fields. Cassandra treats the value of a frozen type as a blob. The entire value must be overwritten.
此外,Cassandra 不支持集合中的非冻结字段
来源:https://docs.datastax.com/en/cql/3.1/cql/cql_reference/collection_type_r.html