这是我的场景,考虑我的表有 cloumnsid
主键和clusterkey
集群键。我想删除一条属于主键的记录并插入具有相同主键但不同簇键的新记录。在这种情况下,由于某些并发性,似乎一直没有发生插入?尝试使用时间戳,但同样的问题。
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