How to fix this cypher syntax error:

MATCH (n:Brand)
CASE
  WHEN not exists(n.alias) THEN SET n.hasAlias=0
  ELSE SET n.hasAlias=1
END AS result
return result

What I want is to create a new integer property 'hasAlias' for each node, based upon the existence of the property 'alias'. But I received this error message:

#### Neo.ClientError.Statement.SyntaxError

Invalid input 'S': expected 'l/L' (line 2, column 3 (offset: 15)) "CASE" ^

The problem is that you can't use CASE to perform conditional Cypher, the SET clause (as well as all other clauses) are not allowed. CASE is only used to change what expression gets used.

See the knowledge base entry here:

@andrew_bowman Then perhaps I have to write python code to do the logic externally?

No need, it's actually going to be easier than that.

I only skimmed the query last time, taking a closer look, we can do this with CASE alone, and we don't need conditional Cypher here.

MATCH (n:Brand)
WITH n, CASE WHEN n.alias IS NOT NULL THEN 1 ELSE 0 END as result
SET n.hasAlias = result
RETURN result
2 Likes