Skip to content

Instantly share code, notes, and snippets.

@jexp
Created July 15, 2022 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jexp/73c2da1a2f96d4f54dc7d1d5a75a9bf3 to your computer and use it in GitHub Desktop.
Save jexp/73c2da1a2f96d4f54dc7d1d5a75a9bf3 to your computer and use it in GitHub Desktop.
Common Neo4j Cypher Problems and their Solutions

Most frequent issues in Cypher Statements

How can you prevent this? Check your statements before you run them, best with EXPLAIN that parses them without execution. Use Integration Tests, e.g. with Docker/Testcontainers to check your cypher queries against your current database/dataset.

Slow MERGE

MERGE fails on Null

If you only have a uniqueness constraint, but not an existence constraint on your id

While you can CREATE a node with a null id (why would you), you cannot use MERGE on a null value for an id, it will fail proactively and tell you what field was null.

MERGE (p:Person {id:null})

Error Message: Cannot merge node using null property value for id Solution: You can filter out the null values in your source data, or in your statement before you reach the MERGE, e.g. with WITH * WHERE NOT row.id IS NULL

Missing variable

You misspelled or forgot to declare a variable and try to refer to it later. Or you had it declared in a previous statement which is now gone, they don’t carry over.

CREATE (p:Person {name:'David'});

RETURN p.name;

Error Message: Variable p not defined Solution: Make sure to

Single or Double Quotes in strings

CREATE (:Product {title:"26" TV"})

Will fail because the string has a unescaped double quote

Error Message:

Invalid input 'T': expected whitespace, comment, '.', node labels, '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', '~', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or '}' (line 1, column 38 (offset: 37))
"CREATE (:Product {title:"26" TV"})"
                                   ^

Solution: Either fiddle around with backslash escapes \" or just use parameters instead $title

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment