As of this moment, cql grammar does not provide create keyspace if not exists
. Probably in the future, they will add this feature. The one come close to this, would be this improvement, maybe they will add in for create keyspace too. shrugs
You can probably do something similar using CQL in python or in any Cassandra clients. I have a simple create keyspace if not exists written in java.
try
{
if (cluster.describeKeyspace("new_keyspace") == null)
{
System.out.println("create new keyspace");
KeyspaceDefinition ksdef = HFactory.createKeyspaceDefinition("new_keyspace");
cluster.addKeyspace(ksdef);
}
else
{
System.out.println("keyspace exists");
}
}
catch (HectorException e)
{
}