Jake
Jake

Reputation: 4660

Cassandra: no viable alternative at input 'IF'

This query:

UPDATE jdtestbysentence."sparseSupplement" SET uuid = 2b22da9c-58a6-11e8-ae82-2d3e941502e8 WHERE a_uid = "1849" IF EXISTS

gives this error:

no viable alternative at input 'IF' (...= 2b22da9c-58a6-11e8-ae82-2d3e941502e8 WHERE a_uid = ["184]9" IF...)

I am fairly new to Cassandra. Can someone advise?

Upvotes: 1

Views: 3130

Answers (2)

Aaron
Aaron

Reputation: 57758

UPDATE jdtestbysentence."sparseSupplement"
SET uuid = 2b22da9c-58a6-11e8-ae82-2d3e941502e8 WHERE a_uid = "1849" IF EXISTS

Ok, so I created your table on my local like this:

CREATE TABLE "sparseSupplement" (uuid UUID, a_uid TEXT PRIMARY KEY);

I ran your CQL UPDATE, and sure enough I got the same error message. Essentially, there is some confusion around the use of quotes here. Double quotes are only to be used when enforcing case on a table or column name. When setting or checking the value of a TEXT (a_uid) you should use single quotes around 1849:

cassdba@cqlsh:stackoverflow> UPDATE "sparseSupplement"
    SET uuid = 2b22da9c-58a6-11e8-ae82-2d3e941502e8
    WHERE a_uid = '1849' IF EXISTS;

 [applied]
-----------
     False

Pro-tip: Also, I would caution you against using double-quotes like that. Unless you absolutely need it to match case to a Java class, it's just going to make it more difficult to work with that table. Kind of like it did here.

Upvotes: 4

Payal
Payal

Reputation: 564

I have tried your query with some modification in my test environment and it worked.

UPDATE jdtestbysentence."sparseSupplement" SET uuid = 2b22da9c-58a6-11e8-ae82-2d3e941502e8 WHERE a_uid = '1849' IF EXISTS

Upvotes: 3

Related Questions