Reputation: 99
This is My Table structure as follows
CREATE TABLE manage_files_log (
account_sid uuid,
file_type text,
file_sid timeuuid,
date_created timestamp,
file_description text,
file_name text,
status int,
url text,
PRIMARY KEY ((account_sid, file_type), file_sid)
) WITH CLUSTERING ORDER BY (file_sid DESC)
in this table I want to update my records with query
UPDATE manage_files_log SET url='$url' WHERE account_sid =e40daea7-b1ec-088a-fc23-26f67f2052b9 AND file_type ='json' AND file_sid=961883e0-208f-11e6-9c41-474a6606bc87;
but it is inserting new record instead of updating existing record.
please help Me
below is the example of data in table where I want to update the url column value
account_sid | file_type | file_sid | date_created | file_description | file_name | status | url
--------------------------------------+-----------+------------------- -------------------+--------------------------+------------------+-------- ---+--------+-----
e40daea7-b1ec-088a-fc23-26f67f2052b9 | json | e15e02f0-20ab-11e6-9c41-474a6606bc87 | 2016-05-22 00:00:00+0000 | descripton | testUrl1 | 1 |
Upvotes: 0
Views: 249
Reputation: 2321
Okay, there's one thing you have to know about cassandra: Update or insert don't exist. I know, you write, in your query, update or insert, but it's the same. It's called Upsert. You might think: Whaaat? But there's a reason for this: Cassandra is a masterless distributed database system. You have, generally, no transactions. If you insert a value to node1 and want to update it after 10ms on node2, it could happen that your first value isn't on node2. With a hard UPDATE, your second operation will fail. But cassandra ignores this fact and writes the values to node2. After a time node2 and node1 will synchronizing their values. At this stage node1 gets the right values from node1. (Cassandra uses an internal column timestamp for synchronizing)
But you can also use update as update: Simply add IF EXISTS; to your query. But remember one thing: It's a big performance killer. Cassandra has to read all values from all nodes!
Upvotes: 4