Search code examples
javacassandracql

Cassandra Keyspace name with hyphen (-)


I am using cassandra 1.2.15 version. Using cassandra CQL Java driver I will be creating a keyspace. My problem is I can't able to create a keyspace which contains hyphen (test-hyphen).

Code:

String query = "CREATE KEYSPACE \"test-hyphen\" WITH REPLICATION = { 'class': 'SimpleStrategy', 'replication_factor' : 1 }"
resultSet = session.execute(query)

When I tried to do so I am getting following exception:

java.lang.Exception: com.datastax.driver.core.exceptions.InvalidQueryException: "test-hyphen" is not a valid keyspace name

Any work around or any possible way to create keyspace with hyphen in between the characters?


Solution

  • This cannot be done.

    From the documentation:

    Keyspace names are 32 or fewer alpha-numeric characters and underscores, the first of which is an alpha character. Keyspace names are case-insensitive. To make a name case-sensitive, enclose it in double quotation marks.