Reputation: 689
I have the following neo4j query which check for the relationships count between two nodes:
match (a:T {id:1})-[y:FR]->(b:T {id:3})
match (a)-[x:F]->(b)
return SIGN(COUNT(x)), SIGN(COUNT(y))
In the database, however, there exist both F
and FR
relationships between the nodes, it's returning 0,0?
What's wrong with my query?
Upvotes: 0
Views: 83
Reputation: 30397
If you know for sure that the nodes exist, but you're not sure if the relationships exist, then by doing matches like this you risk eliminating all rows, since a failed MATCH does not generate rows, and removes rows from previous matches that don't fulfill the match.
In your case it's better to match on each node, and then get the SIZE() of the desired relationship types, or if you just need to return whether or not such a relationship exists, return EXISTS() for the given pattern:
match (a:T {id:1}), (b:T {id:3})
return EXISTS((a)-[:F]->(b)), EXISTS((a)-[:FR]->(b))
Of course if you need just 1 or 0 instead of true/false, stick with SIGN(SIZE((a)-[:F]->(b)))
and so on instead.
Upvotes: 1