Mark Needham

Thoughts on Software Development

Neo4j Browser: Expected entity id to be an integral value

without comments

I came across an interesting error while writing a Cypher query that used parameters in the Neo4j browser which I thought I should document for future me.

We’ll start with a graph that has 1,000 people:

unwind range(0,1000) AS id
create (:Person {id: id})

Now we’ll try and retrieve some of those people via a parameter lookup:

:param ids: [0]
match (p:Person) where p.id in {ids}
return p
 
╒════════╕
│"p"     │
╞════════╡
│{"id":0}│
└────────┘

All good so far. Now what about if we try and look them up by their internal node id instead:

match (p:Person) where id(p) in {ids}
return p
 
Neo.ClientError.Statement.TypeError
Expected entity id to be an integral value

Hmm, that was unexpected. It turns out that to get this query to work we need to cast each of the integer values in the {ids} array to a 64 bit integer using the toInteger function:

match (p:Person) where id(p) in [id in {ids} | toInteger(id)]
return p
 
╒════════╕
│"p"     │
╞════════╡
│{"id":0}│
└────────┘

Success!

Be Sociable, Share!

Written by Mark Needham

November 6th, 2017 at 4:17 pm

Posted in neo4j

Tagged with , ,