Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j/Cypher: Convert string to double

Tags:

neo4j

cypher

I have stored a double (-0.1643) as string ("-0.1643") in a property on a neo4j relationship.

If I try to filter on this value with a numeric comparison:

MATCH (n1:Node)-[r:RELATION]-(n2:Node)
WHERE r.number < -0.1 RETURN n1, n2

Cypher throws an error:

Don't know how to compare that. Left: "-0.1643" (String); Right: -0.1 (Double)
Neo.ClientError.Statement.InvalidSyntax

Obviously, I could store the data as a numeric value. But is it possible to convert the string to double in cypher? Something like:

MATCH (n1:Node)-[r:RELATION]-(n2:Node)
WHERE as.double(r.number) < -0.1 RETURN n1, n2
like image 262
Martin Preusse Avatar asked Jan 25 '14 10:01

Martin Preusse


2 Answers

Check out release 2.0.2. It added to type functions, "toInt, toFloat, toStr". It looks like toDouble doesn't exist, but perhaps float is precise enough for you?

http://www.neo4j.org/release-notes#2.0.2

like image 121
Wouter Avatar answered Sep 18 '22 20:09

Wouter


you can use this:

RETURN toFloat("0.0125")

like image 20
Wesam Na Avatar answered Sep 20 '22 20:09

Wesam Na