Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-12-2020 07:20 AM
Hello,
In my graph, relationships have a property named list
. list
is an array of int.
It looks like this:
(head:Node)-[r:RELATIONSHIP {list:...}]->(tail:Node)
I'd like to query all tails in the graph, where the sum of list
is > 0.
Intuitively, I would do:
MATCH (:Node)-[r:RELATIONSHIP]->(tail:Node)
WHERE sum(r.list) > 0
RETURN tail
This does not work unfortunately. It throws an error. How can I write this query?
Thanks
Solved! Go to Solution.
11-12-2020 05:03 PM
MATCH (head:Node)
CALL {
WITH head
MATCH (head)-[r:RELATIONSHIP]->(tail:Node)
WHERE apoc.coll.sum(r.list) > 0
RETURN tail
}
RETURN tail
11-12-2020 05:03 PM
MATCH (head:Node)
CALL {
WITH head
MATCH (head)-[r:RELATIONSHIP]->(tail:Node)
WHERE apoc.coll.sum(r.list) > 0
RETURN tail
}
RETURN tail
11-13-2020 10:16 AM
Newbie question:
Is there an explanation of what's wrong with the original solution and why you need an apoc
call to solve the problem? (I'm also curious as to what the error was. If I get around to trying this out, I'll post the errmsg.)
I'm not sure why apoc calls are needed here. I get the feeling this is a bit similar to SQL in Spark with UDF's, but my intuition on all this isn't well developed yet.
Thanks.
All the sessions of the conference are now available online