Neo4j: Cypher - Neo.ClientError.Statement.TypeError: Don't know how to add Double and String
I recently upgraded a Neo4j backed application from Neo4j 3.2 to Neo4j 3.3 and came across an interesting change in behaviour around type coercion which led to my application throwing a bunch of errors.
In Neo4j 3.2 and earlier if you added a String to a Double it would coerce the Double to a String and concatenate the values. The following would therefore be valid Cypher:
RETURN toFloat("1.0") + " Mark"
╒══════════╕
│"result" │
╞══════════╡
│"1.0 Mark"│
└──────────┘
This behaviour has changed in the 3.3 series and will instead throw an exception:
RETURN toFloat("1.0") + " Mark"
Neo.ClientError.Statement.TypeError: Don't know how to add `Double(1.000000e+00)` and `String(" Mark")`
We can workaround that by forcing our query to run in 3.2 mode:
CYPHER 3.2
RETURN toFloat("1.0") + " Mark" AS result
or we can convert the Double to a String in our Cypher statement:
RETURN toString(toFloat("1.0")) + " Mark" AS result
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.