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

Download the Altoros NoSQL Performance Benchmark 2018. Compare top NoSQL solutions – Couchbase Server v5.5, MongoDB v3.6, and DataStax Enterprise v6 (Cassandra).

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

Download the whitepaper, Moving From Relational to NoSQL: How to Get Started. We’ll take you step by step through your first NoSQL project.

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 }}