Amitkumar Satpute
Amitkumar Satpute

Reputation: 144

Cassandra Update Record : Non PRIMARY KEY columns found

I created table in Cassandra database name as information_tbl. query:

CREATE TABLE IF NOT EXISTS Information_tbl (id uuid ,
                                      cam_id varchar,
                                      camzone varchar,
                                      msg varchar,
                                      fltr int,
                                      time_stamp int,
                                      PRIMARY KEY (fltr,time_stamp)
                                      )WITH CLUSTERING ORDER BY (time_stamp DESC);

when I execute update query, it show error :

Query 1:

UPDATE information_tbl SET camzone = 'D' WHERE id = c6263cac-450f-4105-a2cc-3705ec741a96;

Error:

message="Some partition key parts are missing: fltr"

Query 2:

UPDATE information_tbl SET camzone = 'D' WHERE fltr=1 AND id = c6263cac-450f-4105-a2cc-3705ec741a96;

Error:

message="Some clustering keys are missing: time_stamp"

Query 3:

UPDATE information_tbl SET camzone = 'D' WHERE fltr=1 AND time_stamp = 1581946832 AND id = c6263cac-450f-4105-a2cc-3705ec741a96;

Error:

message="Non PRIMARY KEY columns found in where clause: id "

Any suggestions.

Upvotes: 0

Views: 1689

Answers (3)

Samual
Samual

Reputation: 67

If you want to update table fields you must need primary key in where clouse for that. If you do not have it first get it(primary key field value) using select query(you can use select query without primary key) and then use update query on the basis of that primary key.

Upvotes: 0

Venkat
Venkat

Reputation: 73

To update Cassandra row in Cassandra, you need Partition Key + Clustering Key. Coming to you error messages

Error 1 : message="Some partition key parts are missing: fltr" in this case you are not passing any partition key columns.

Error 2 : message="Some clustering keys are missing: time_stamp" in this case you are passing a part of partition key columns.

Error 3 : message="Non PRIMARY KEY columns found in where clause: id " in this case you are passing partition key columns along with other columns.

If you have the value of ID available, you can change your data model as below to perform an update.

CREATE TABLE IF NOT EXISTS Information_tbl (id uuid ,
                                      cam_id varchar,
                                      camzone varchar,
                                      msg varchar,
                                      fltr int,
                                      time_stamp int,
                                      PRIMARY KEY (id, fltr,time_stamp)
                                      )WITH CLUSTERING ORDER BY (time_stamp DESC);

Upvotes: 1

Carlos Monroy Nieblas
Carlos Monroy Nieblas

Reputation: 2283

In the 3 queries provided, you are treating the column id as if it was part of the primary key; here is a succinct explanation of their characteristic. You may also visit the data model explanations in DS201 of DataStax Academy.

From the query example 2, it looks that fltr may have a low cardinality, which will also be troublesome, please refer to this explanation.

Upvotes: 2

Related Questions