Over a million developers have joined DZone.

Neo4j Cypher Error: Don't Know How to Add Double and String [Code Snippets]

DZone's Guide to

Neo4j Cypher Error: Don't Know How to Add Double and String [Code Snippets]

Learn how to deal with the Neo.ClientError.Statement.TypeError error in Neo4j, which involves not knowing how to add a Double and String in Cypher.

· Database Zone ·
Free Resource

Running out of memory? Learn how Redis Enterprise enables large dataset analysis with the highest throughput and lowest latency while reducing costs over 75%! 

I recently upgraded a Neo4j-backed application from Neo4j 3.2 to Neo4j 3.3 and came across an interesting change in behavior 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 behavior 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 work around that by forcing our query to run in 3.2 mode:

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

Running out of memory? Never run out of memory with Redis Enterprise databaseStart your free trial today.

database ,neo4j ,cypher ,error

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}