Enterprise Java
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 resultor we can convert the Double to a String in our Cypher statement:
RETURN toString(toFloat("1.0")) + " Mark" AS result| Published on Java Code Geeks with permission by Mark Needham, partner at our JCG program. See the original article here: Neo4j: Cypher – Neo.ClientError.Statement.TypeError: Don’t know how to add Double and String Opinions expressed by Java Code Geeks contributors are their own. |




