Filter based on sum of array relationship property

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

MATCH (head:Node)
CALL {
WITH head
MATCH (head)-[r:RELATIONSHIP]->(tail:Node)
WHERE apoc.coll.sum(r.list) > 0
RETURN tail
}
RETURN tail

1 Like

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.