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?
The ALTER TABLE command can be used to add new columns to a table and to alter the column type of an existing column.
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.
Cassandra Create Data INSERT command is used to insert data into the columns of the table. Syntax: INSERT INTO <tablename> (<column1 name>, <column2 name>....)
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With