cassandra add column if not exists
Asked Answered
P

1

20

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?

Plainsong answered 8/9, 2014 at 16:32 Comment(2)
You can file a feature request at issues.apache.org/jira/browse/CASSANDRASadonia
This question has already been answered in another post. See: https://mcmap.net/q/663443/-does-it-have-an-equivalent-query-in-cql-cassandra-for-quot-alter-table-add-column-if-column-not-exists-quotMayce
T
29

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.

Tumescent answered 8/9, 2014 at 18:39 Comment(1)
Yea that works. My assumption was that an error would halt the script mid flow. I guess the lesson here is to try before you cry.Plainsong

© 2022 - 2024 — McMap. All rights reserved.