CASSANDRA CQL3: set value for whole column

For my Cassandra database, I need to set a value in a column for all rows in my table.

I see in SQL we can do:

UPDATE table SET column1= XXX;

      

but in CQL (in cqlsh), it doesn't work! I don't want to update line by line up to 9500 lines.

Do you have any suggestions?

Thank:)

+3


source to share


2 answers


As you will know, CQL! = SQL. It is not possible to accomplish what you are asking in CQL except to iterate over every row in the table.

Robert's suggestion for an override column1

for a static column might help. But static columns are bound to their section key, so you would still need to specify that:

aploetz@cqlsh:stackoverflow2> UPDATE t SET s='XXX' WHERE k='k';

      



Also, it looks like you only want to set the column value for all rows. A static column won't work for you if you want the column value to be different for the CQL strings in the section (from an example in the DataStax docs):

aploetz@cqlsh:stackoverflow2> INSERT INTO t (k, s, i) VALUES ('k', 'I''m shared', 0);
aploetz@cqlsh:stackoverflow2> INSERT INTO t (k, s, i) VALUES ('k', 'I''m still shared', 1);
aploetz@cqlsh:stackoverflow2> SELECT * FROM t;

 k | i | s
---+---+------------------
 k | 0 | I'm still shared
 k | 1 | I'm still shared

(2 rows)

      

Note that the column value is the s

same for all CQL rows under the section key k

. You just understand how it works.

0


source


You can use an update query with an IN clause instead of running query 9500. First select the primary_key from your table and then copy the values ​​into this query:



UPDATE table SET column1 = XXX WHERE primary_key IN (p1, p2, p3, ...);

      

+3


source







All Articles