How to insert a new column to a row using CQL

1.1k Views Asked by At

i would like to know how to use CQL to insert a new column to a row...

Is it possible? If not, how can i do that easily by using Fluent Cassandra?

Thanks.

3

There are 3 best solutions below

2
On

CQL expects you to define your schema up front. If you want dynamic schema, you must use one of the Thrift-based clients. Fluent Cassandra supports this; check here.

1
On

Using FluentCassandra, you can add a new column to an existing row quite easily:

var cFamily = db.GetColumnFamily("TestCF");
cFamily.InsertColumn(rowKey, columnName, columnValue);

Alternatively, you can do it like this:

var cFamily = db.GetColumnFamily("TestCF");
var record = cFamily.CreateRecord(existingRowKey) //record already exists
record[newColumnName] = newColumnValue;
0
On

Using FluentCassandra:

dbcontext.ExecuteNonQuery("update TargetColumnFamily set 'ColumnName'='ColumnValue' 
   where keyname='RowKeyValue'")

In my testing, I've found this will create the row if it doesn't exist. Not sure how to tweak this for non-text.