cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to fix this cypher syntax error:

lingvisa
Graph Fellow
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" ^
1 ACCEPTED SOLUTION

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

View solution in original post

3 REPLIES 3

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