5

I am using below CQL syntax to create keyspace only if does not exists :

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

but it is giving error :

Exception in thread "main" com.datastax.driver.core.exceptions.SyntaxError: line 1:23 extraneous input 'EXISTS' expecting '='
at com.datastax.driver.core.exceptions.SyntaxError.copy(SyntaxError.java:35)
at com.datastax.driver.core.DefaultResultSetFuture.extractCauseFromExecutionException(DefaultResultSetFuture.java:256)
at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:172)
at com.datastax.driver.core.SessionManager.execute(SessionManager.java:91)
at com.datastax.driver.core.SessionManager.execute(SessionManager.java:83)

please help me on this ? whats wrong with syntax ?

Sanjiv
  • 1,795
  • 1
  • 29
  • 45

2 Answers2

2

That does appear to be the proper syntax (ref: docs). I've just tried it myself on Cassandra 2.0.7.

The "if not exists" option is part of CQL3 which first came with Cassandra 1.2. I would double check your Cassandra version to see if this option is available.

BrianC
  • 10,591
  • 2
  • 30
  • 50
1

If you encounter this same SyntaxError (AND you use Eclipse) make sure first that your Eclipse IDE does not export with Cp1252 character encoding but UTF-8 (or any other encoding matching that of your Cassandra ring (usually UTF-8)

DataHacker
  • 276
  • 2
  • 10