【发布时间】:2018-08-11 04:41:49
【问题描述】:
这是我的场景,考虑我的表有 id 主键和 clusterkey 集群键的 cloumns。我想删除一条属于主键的记录,并插入具有相同主键但不同簇键的新记录。在这种情况下,由于某些并发性,似乎插入没有发生?尝试使用时间戳,但同样的问题。
const query1 = 'delete from table where id=? and clusterkey=?';
const query2 = 'INSERT INTO table (id, clusterkey, name) VALUES (?, ?, ?)';
const queries = [
{ query: query1, params: ['1', '3'] },
{ query: query2, params: ['1', '8', 'GoodName'] }
];
client.batch(queries, { prepare: true }, function (err) {
console.log(err, 'done')
});
使用时间戳
const query1 = 'delete from table where id=? and clusterkey=? using timestamp ?';
const query2 = 'INSERT INTO table (id, clusterkey, name) VALUES (?, ?, ?) using timestamp ?';
const queries = [
{ query: query1, params: ['1', '3', Date.now() * 1000] },
{ query: query2, params: ['1', '8', 'GoodName', Date.now() * 1000] }
];
client.batch(queries, { prepare: true }, function (err) {
console.log(err, 'done')
});
表信息:
create table sample (id text, group text, name text, PRIMARY KEY (id, group))
查询结果:
批处理前选择结果
id |clusterkey |name
-----------------------------
1 |3 |wrongname
2 |2 |Hello
批处理后
id |clusterkey |name
-----------------------------
2 |2 |Hello
【问题讨论】:
-
能否提供第一种情况
(id, clusterkey, name)的表结构。 -
create table sample (id text, group text, name text, PRIMARY KEY (id, group)) -
@PasupathiRajamanickam 你能在这个批处理执行后做一个选择并提供结果吗?
-
@dilsingi 更新了我的问题。
标签: node.js cassandra cassandra-3.0 cassandra-driver