Search code examples
cassandraatomic

Cassandra If clause conditon from different table


i have to Update /Insert data in shopping_cart table only if some quantity is present in inventory table in cassandra , and this needs to be atomic operation as the invetory table is being updated frequently , I was trying to use a light weight transaction some thing like below

update shopping_cart
set 
quantity=1
where
item='item1'
if
 (select quantity from inventory where item='item1') = 2;

but i am getting an error

mismatch input '(' expecting K_NOT 

probably light weight transaction is not the best way to do this also i think that if clause would not be supporting query from different table in cassandra .

so what would be the best way to achive the above operation in cassandra without compromising on atomicty .


Solution

  • Above type of a query wont be possible - two options I can think of,

    1. Keep the quantity in the shopping_cart table also when you want to update the quantity use a batch statement to update in both tables.
    2. Handling this in the application itself but will have more pain.