Reputation: 35
I am trying to set new properties based on existing properties. The existing nodes have the following properties:
minTempC
, maxTempC
New properties should be set if the following conditions are met:
minTempC < 0
set the property frosstag = true
maxTempC < 0
set the property eistag = true
maxTempC >= 30
set the property heissertag = true
The existing nodes can meet one, multiple or none of the conditions.
My cypher right now is:
//Eistag
MATCH (d:Data)
WHERE d.maxtempC < 0
SET d += {eistag:true}
//Frosttag
MATCH (d:Data)
WHERE d.mintempC < 0
SET d += {frosttag:true}
//Heisser Tag
MATCH (d:Data)
WHERE d.maxtempC >= 30
SET d += {heisserTag:true}
Is there a way to combine these three? I have several other properties that have to be set and writing these SET
clauses over and over again seems a little bit tedious. I thought of using a CASE
expression, but I am new to neo4j and must confess that I have no idea how to built such a expression.
Thank you in advance for yout tips.
Upvotes: 3
Views: 1429
Reputation: 39925
You can use CASE WHEN
in an expression, so the following should help:
MATCH (d:Data)
SET
d.eistag = CASE WHEN d.minTempC < 0 THEN true END,
d.frosttag = CASE WHEN d.maxTempC < 0 THEN true END,
d.heisserTag = CASE WHEN d.maxTempC >= 0 THEN true END
Note that if the condition is false, a null
is returned from CASE WHEN
. Setting a property to a null
value results in not setting this property.
Upvotes: 2