Sharanya Vijay
Sharanya Vijay

Reputation: 1

need to insert record for a column if exists update record on differnt column in cassandra

i have a table similar to below where name is the primary key

name    pay creation date   update date
mike    1000    3/1/2020    3/1/2020

i need to insert multiple records to the table and if record already exists i need to update the row. The challenge is create date. Create date should not be updated, it is just needs to be inserted. i am using simple update query like

update table_name set pay=2000,creation date=sys date,update date=sysdate where name='mike';

Upvotes: 0

Views: 655

Answers (1)

Alex Ott
Alex Ott

Reputation: 87154

In Cassandra there is no difference between INSERT and UPDATE (if you're not using lightweight transactions) - everything is UPSERT. This means, that if you do INSERT and row exists, then data will be updated, and if you do UPDATE and row doesn't exist, it will be created. So, for your problem - you can just perform INSERTs without worrying about checking if row exists, and doing UPDATE instead of INSERT.

Upvotes: 1

Related Questions