CQL: how to check if keyspace exists?

Yury Pogrebnyak picture Yury Pogrebnyak · Mar 11, 2012 · Viewed 19.1k times · Source

I need to check if certain keyspace exists in Cassandra database. I need to write smth like this:

if (keyspace KEYSPACE_NAME not exists) create keyspace KEYSPACE_NAME;

There's a command describe keyspace, but can I somehow retrieve information from it in cql script?

Answer

fgakk picture fgakk · Oct 6, 2013

Just providing fresh information. As of CQL3 while creating a keyspace you can add if statement like this

CREATE KEYSPACE IF NOT EXISTS Test
    WITH replication = {'class': 'SimpleStrategy',
                        'replication_factor' : 3}