Here is my scenario, consider my table has cloumns id
primary key and clusterkey
cluster key. I want to delete one record falling under primary key and insert new record with same primary key but different cluster key. In this case, all the time it looks like insert is not happening due to some concurrency? Tried using Timestamp, but same issue.
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')
});
Using Timestamp
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')
});
Table Info:
create table sample (id text, group text, name text, PRIMARY KEY (id, group))
Query Results:
select result before batch
id |clusterkey |name
-----------------------------
1 |3 |wrongname
2 |2 |Hello
After batch
id |clusterkey |name
-----------------------------
2 |2 |Hello