如何在Cassandra中更新和替换UDT字段值?

如何在Cassandra中更新和替换UDT字段值?,cassandra,Cassandra,Cassandra是否支持UDT字段值的更新?比如用新值替换它 我有用户付款方式UDT,我需要用借记卡替换现金: update user_ratings set user_fav_payment_method{'cash'} = {'debit cards'} where rating_id = 66; 此代码错误,但我需要执行类似的操作,如何执行此操作?Per: 在Cassandra 3.6及更高版本中,仅包含非集合字段的用户定义类型可以更新单个字段值。使用Update命令更新用户定义类型

Cassandra是否支持UDT字段值的更新?比如用新值替换它

我有用户付款方式UDT,我需要用借记卡替换现金:

update user_ratings set 
user_fav_payment_method{'cash'} = {'debit cards'}
where rating_id = 66;
此代码错误,但我需要执行类似的操作,如何执行此操作?

Per:

在Cassandra 3.6及更高版本中,仅包含非集合字段的用户定义类型可以更新单个字段值。使用Update命令更新用户定义类型数据中的单个字段。所需的键值对在命令中定义。为了更新,必须在CREATE TABLE命令中将UDT定义为未冻结的数据类型

您可以使用
表示法仅更新非冻结UDT的各个字段,如下所示:

cqlsh> use test;
cqlsh:test> create type payment_method ( method text, data text);
cqlsh:test> create table users (id int primary key, pay_method payment_method);
cqlsh:test> insert into users (id, pay_method) values (1, {method: 'cash', data: 'usd'});
cqlsh:test> select * from users;

 id | pay_method
----+-------------------------------
  1 | {method: 'cash', data: 'usd'}

(1 rows)

cqlsh:test> update users set pay_method.method = 'card' where id = 1;
cqlsh:test> select * from users;

 id | pay_method
----+-------------------------------
  1 | {method: 'card', data: 'usd'}

(1 rows)
Per:

在Cassandra 3.6及更高版本中,仅包含非集合字段的用户定义类型可以更新单个字段值。使用Update命令更新用户定义类型数据中的单个字段。所需的键值对在命令中定义。为了更新,必须在CREATE TABLE命令中将UDT定义为未冻结的数据类型

您可以使用
表示法仅更新非冻结UDT的各个字段,如下所示:

cqlsh> use test;
cqlsh:test> create type payment_method ( method text, data text);
cqlsh:test> create table users (id int primary key, pay_method payment_method);
cqlsh:test> insert into users (id, pay_method) values (1, {method: 'cash', data: 'usd'});
cqlsh:test> select * from users;

 id | pay_method
----+-------------------------------
  1 | {method: 'cash', data: 'usd'}

(1 rows)

cqlsh:test> update users set pay_method.method = 'card' where id = 1;
cqlsh:test> select * from users;

 id | pay_method
----+-------------------------------
  1 | {method: 'card', data: 'usd'}

(1 rows)