Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4J Cypher data type conversion

Tags:

neo4j

cypher

I've got a property quantity on our Product-nodes and am looking to do a cypher query that gives me all nodes with quantity = 20 ... problem is that quantity is stored as a string in neo4j. Is there a way to cast the property to integer in the cypher query?

// This fails to find the required nodes
MATCH (p:Product) WHERE p.quantity = 20;

// This finds them
MATCH (p:Product) WHERE p.quantity = "20";

// I would like to do this
MATCH (p:Product) WHERE INT(p.quantity) = 20;

PS: this is a really simplified usecase, we don't really have products and quantities but are just faced with existing neo4j data that has integer values stored as strings, and we would like to do some matches on these strings

like image 978
ChrisR Avatar asked Jan 15 '14 08:01

ChrisR


2 Answers

You can do it the other way round.

MATCH (p:Product) WHERE p.quantity = str(20) RETURN p;

should also work with params.

MATCH (p:Product) WHERE p.quantity = str({quantity}) RETURN p;

or even with inline property matches

MATCH (p:Product {quantity : str({quantity})}) RETURN p;
like image 175
Michael Hunger Avatar answered Sep 18 '22 18:09

Michael Hunger


MATCH (p:Product) WHERE toInt(p.quantity) = 20;
like image 38
Ashish Barde Avatar answered Sep 20 '22 18:09

Ashish Barde