I'm a beginner in Cassandra and I have a table like this:
CREATE TABLE Books(
Title text PRIMARY KEY,
Authors set<text>,
Family set <text>,
Publisher text,
Price decimal
);
(the other options are missing because it's only an example)
now I would like to execute this query:
DELETE Price FROM Books WHERE Authors CONTAINS 'J.K. Rowling' IF EXISTS;
But it doesn't work. I searched on Google but found nothing.
Hope somebody can help me and sorry if my english is not very good.
That doesn't really give us enough information to help you. Usually, you'll want to provide an error message. I built your table locally, inserted data, and tried your approach. This is the error that I see:
DELETErequires that the appropriate PRIMARY KEY components be specified in theWHEREclause. In your case,Authorsis not part of the PRIMARY KEY definition. Given the error message returned (and the table definition) specifyingtitleis the only way to delete rows from this table.No. This fails for the same reason. Writes in Cassandra (INSERTs, UPDATEs, DELETEs are all writes) require the primary key (specifically, the partition key) in the
WHEREclause. Without that, Cassandra can't figure out which node holds the data, and it needs that to perform the write.