Skip to content

Commit

Permalink
Cypher: Rewrite NULL checks in CASE statements
Browse files Browse the repository at this point in the history
Neo4j v5.1 comes with the following deprecation notice:

> Using null as an expression to be compared against in a CASE expression is deprecated and from 5.0 will no longer match on anything. Try using a generic CASE with `IS NULL` instead. For example 'CASE WHEN n.prop IS NULL THEN true ELSE false END'.
  • Loading branch information
szarnyasg committed Nov 21, 2022
1 parent 5673c5b commit 5155230
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cypher/queries/bi-14.cypher
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ MATCH
WITH person1, person2, city1, 0 AS score
// case 1
OPTIONAL MATCH (person1)<-[:HAS_CREATOR]-(c:Comment)-[:REPLY_OF]->(:Message)-[:HAS_CREATOR]->(person2)
WITH DISTINCT person1, person2, city1, score + (CASE c WHEN null THEN 0 ELSE 4 END) AS score
WITH DISTINCT person1, person2, city1, score + (CASE WHEN c IS NUL THEN 0 ELSE 4 END) AS score
// case 2
OPTIONAL MATCH (person1)<-[:HAS_CREATOR]-(m:Message)<-[:REPLY_OF]-(:Comment)-[:HAS_CREATOR]->(person2)
WITH DISTINCT person1, person2, city1, score + (CASE m WHEN null THEN 0 ELSE 1 END) AS score
WITH DISTINCT person1, person2, city1, score + (CASE WHEN m IS NULL THEN 0 ELSE 1 END) AS score
// case 3
OPTIONAL MATCH (person1)-[:LIKES]->(m:Message)-[:HAS_CREATOR]->(person2)
WITH DISTINCT person1, person2, city1, score + (CASE m WHEN null THEN 0 ELSE 10 END) AS score
WITH DISTINCT person1, person2, city1, score + (CASE WHEN m IS null THEN 0 ELSE 10 END) AS score
// case 4
OPTIONAL MATCH (person1)<-[:HAS_CREATOR]-(m:Message)<-[:LIKES]-(person2)
WITH DISTINCT person1, person2, city1, score + (CASE m WHEN null THEN 0 ELSE 1 END) AS score
WITH DISTINCT person1, person2, city1, score + (CASE WHEN m IS null THEN 0 ELSE 1 END) AS score
// preorder
ORDER BY
city1.name ASC,
Expand Down

0 comments on commit 5155230

Please sign in to comment.