CodePlorer
CodePlorer

Reputation: 163

Unable to delete data from a Cassandra CF

So I have a CF whose Schema looks something like this :

CREATE TABLE "emp" (
id text,
column1 text,
column2 text,
PRIMARY KEY (id, column1, column2)
)

I have an entry which looks like this and I want to delete it :

20aff8144049 | name | someValue

So i tried this command :

Delete column2 from emp where id='20aff8144049';

It failed with below error:

no viable alternative at input '20aff8144049' (...column2 from emp where id=["20aff8144049]...)

Can someone help with where I'm going wrong? Thanks!

Upvotes: 1

Views: 125

Answers (2)

Marcus
Marcus

Reputation: 53

You only can delete an entry using a valid value for your primary key. You defined your primary key to include (id, column1, column2) which means that you have to put all the corresponding values in your where clause.

However, I assume you wanted to be able to delete by id only. Therefore, I'd suggest you re-define your column family like this:

CREATE TABLE "emp" (
    id text,
    column1 text,
    column2 text,
    PRIMARY KEY ((id), column1, column2)
)

where id is your partition key and column1 and column2 are your clustering columns.

Upvotes: 3

Ashraful Islam
Ashraful Islam

Reputation: 12840

You can't delete or set null to primary key column

You have to delete the entire row.

Upvotes: 3

Related Questions