Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-25-2021 03:01 PM
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" ^
Solved! Go to Solution.
05-25-2021 03:35 PM
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
05-25-2021 03:16 PM
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:
05-25-2021 03:22 PM
@andrew.bowman Then perhaps I have to write python code to do the logic externally?
05-25-2021 03:35 PM
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
All the sessions of the conference are now available online