Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cassandra add column if not exists

Tags:

I need to insert a new column into an existing column family via a CQL script.

I want to do something like:

alter COLUMNFAMILY rules ADD rule_template text IF NOT EXISTS;

How can I achieve this purely in CQL script?

like image 620
beterthanlife Avatar asked Sep 08 '14 16:09

beterthanlife


People also ask

How do I add a new column in Cassandra?

The ALTER TABLE command can be used to add new columns to a table and to alter the column type of an existing column.

Which command is work the same as if not exists in Cassandra?

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.

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>....)

What is Cqlsh?

cqlsh is a command-line interface for interacting with Cassandra using CQL (the Cassandra Query Language). It is shipped with every Cassandra package, and can be found in the bin/ directory alongside the cassandra executable.


1 Answers

There is no optional "if not exists" for altering column families (tables). As a workaround you could just execute the alter command and ignore the error if the column already exists. There shouldn't be any harm in it, other than the error message.

like image 69
BrianC Avatar answered Sep 23 '22 02:09

BrianC