CASE can't be used for conditional Cypher execution like you're doing here (you can't have SET clauses within it).
You can use CASE to produce a different expression depending on the evaluation, which would make more sense if you were attempting to set one of two different values to the same property, but in this case you're setting different properties depending on the evaluation.
Or you can use a trick using FOREACH, which relies on the fact that the FOREACH contents will execute per element in the list, so we use CASE to emit a single element list (to trigger the updating Cypher) or an empty list (no-op). Be aware you need a separate FOREACH for each condition, including the else case:
MATCH (n:Node)
// blah, blah, blah
FOREACH (ignoreme in CASE WHEN n.foo = 'foo' THEN [1] ELSE [] END |
SET n.one = 'one')
FOREACH (ignoreme in CASE WHEN n.foo <> 'foo' THEN [1] ELSE [] END |
SET n.two = 'two')
Thanks. I will try with FOREACH. But most of the time I get answer with APOC. This is what I am not using. Can you please guide when I must use this plugin?
APOC is a library of procedures and functions, a kind of swiss-army-knife/wishlist of features we want (and in some cases need) that aren't in the main product but that we can create with custom user procedures and functions.
There is so much in there I can't articulate all of its functionality along with what's convenient vs what's essential (lacking a non-APOC means to accomplish it), but here are a couple notable pieces of functionality that can't yet be replicated with just Cypher:
Batching (when not using CSVs) using apoc.periodic.iterate(). You CAN actually do this in Cypher, but manually, adding LIMIT within your queries, designing them correctly, and executing manually as many times as it takes to process all batches.
JSON handling, both transforming from and to.
Advanced path expansion options. Cypher follows a certain expansion behavior when expanding out, in that a relationship must be unique per path. APOC's path expanders allow different behavior that may be required for specific use cases, usually ones having to do with expanding out to a subgraph efficiently, or finding a distinct count of certain kinds of nodes reachable or within some distance, or when you need to expand out to repeating patterns of node types or relationships.