Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-22-2020 12:57 PM
I'm puzzled about CASE WHEN
.
This works (I added the parens the expression that RETURN
returns to clarify).
MATCH (n)
RETURN
(CASE n.eyes
WHEN 'blue'
THEN 1
WHEN 'brown'
THEN 2
ELSE 3 END) AS result
but this doesn't work (syntax error). I'm not clear why. CASE
is not expected to follow MATCH
(but CALL
is)
MATCH (n)
CASE n.eyes
WHEN 'blue'
THEN 1
WHEN 'brown'
THEN 2
ELSE 3 END as result
RETURN result
It looks like I should use apoc.do.case()
instead, which is described here:
The documentation on this stuff is a bit lacking and not easy to understand:
Solved! Go to Solution.
12-22-2020 04:46 PM
to avoid the syntax error of
MATCH (n)
CASE n.eyes
WHEN 'blue'
THEN 1
WHEN 'brown'
THEN 2
ELSE 3 END as result
RETURN result
rewrite this as
MATCH (n)
with n,
CASE n.eyes
WHEN 'blue'
THEN 1
WHEN 'brown'
THEN 2
ELSE 3 END as result
RETURN result
12-22-2020 04:46 PM
to avoid the syntax error of
MATCH (n)
CASE n.eyes
WHEN 'blue'
THEN 1
WHEN 'brown'
THEN 2
ELSE 3 END as result
RETURN result
rewrite this as
MATCH (n)
with n,
CASE n.eyes
WHEN 'blue'
THEN 1
WHEN 'brown'
THEN 2
ELSE 3 END as result
RETURN result
12-23-2020 09:50 AM
Thanks! The documentation could be improved on this. I'm tempted to redo the documentation and make a Pull Request so that the documentation uses the Movie DB so that a user can more easily try it out.
Would that be OK?
12-23-2020 10:14 AM
ill report to the documentation team. i can see where improvements would help since my response was not the 1 second response but rather took some fiddling to get it right...a minute or 2
All the sessions of the conference are now available online