Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CASSANDRA CQL3 : Set value to entire column

For my Cassandra Database, I need to set a value in 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 row by row until 9500 rows.

Do you have any suggestion ?

Thank you :)

like image 878
Quentin DESBOIS Avatar asked Aug 05 '15 14:08

Quentin DESBOIS


People also ask

How do I update my Cassandra value?

UPDATE writes one or more column values to a row in a Cassandra table. Like INSERT, UPDATE is an upsert operation: if the specified row does not exist, the command creates it. All UPDATEs within the same partition key are applied atomically and in isolation.

How do you add values to a table in Cassandra?

Cassandra Create Data INSERT command is used to insert data into the columns of the table. Syntax: INSERT INTO <tablename> (<column1 name>, <column2 name>....)

How do I change the datatype of a column in Cassandra?

In Cassandra, to modify a column by executing an ALTER statement. Using ALTER table statement You can change the type of a column, Add a new column, Drop a column, Rename existing column as shown here: ALTER TABLE [keyspace_name.]

How do you update multiple columns in Cassandra?

The UPDATE SET operation is not valid on a primary key field. Specify other column values using SET. To update multiple columns, separate the name-value pairs using commas.


1 Answers

You can use update query with IN clause instead of executing 9500 query. At first select primary_key from your table and then copy values to this query:

UPDATE table SET column1 = XXX WHERE primary_key IN (p1, p2, p3, ...);
like image 125
hamid147 Avatar answered Sep 23 '22 11:09

hamid147