1

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?

1
  • It’s mostly comes when you have some syntax error so please check Commented May 18, 2018 at 15:13

2 Answers 2

4
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.

Sign up to request clarification or add additional context in comments.

Comments

3

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.