How to update clustering key in cassandra using update query?

12,081

Based on how Cassandra stores the data, updating clustering columns (Primary key) is not possible.

Rowkey which is a combination of **styleid** ->[sequence] -> [active boolean,image ascii, name ascii]

In order to point non-primary columns for updating/deleting, it needs to parse through styleid -> sequence partition to hit the columns.

Primary key once created can't be changed as it represents how data is stored in Cassandra. Hence updating 'sequence' here is not possible.

Share:
12,081

Related videos on Youtube

Vicky Singh Gill
Author by

Vicky Singh Gill

Updated on September 16, 2022

Comments

  • Vicky Singh Gill
    Vicky Singh Gill over 1 year

    This is my table structure and I am updating the sequence with the following query:

    Update styles set sequence=1 where styleid = 'CLASSIC';
    

    I am getting error message as

    PRIMARY KEY part sequence found in SET part
    Missing PRIMARY KEY part sequence
    
    CREATE TABLE styles (
      styleid ascii,
      sequence int,
      active boolean,
      image ascii,
      name ascii,
      PRIMARY KEY (styleid, sequence)
    ) WITH CLUSTERING ORDER BY (sequence DESC);
    

    Please anyone help me to update the clustering key sequence so that it will be updated. Or any alternative method please share.