Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-11-2021 12:13 PM
To test whether a Relationship has one or another label has two possible solutions:
MATCH(n)-[r:ACTED|DIRECTED]-(m)
RETURN count(r)
and
MATCH(n)-[r]-(m)
WHERE r:ACTED_IN OR r:DIRECTED
RETURN count(r)
But to test whether a Node has one or the other label has only one solution:
MATCH(n)
WHERE n:Movie OR n:Person
RETURN count(n)
This doesn't work. Why not?
MATCH(n:Movie|Person)
RETURN count(n)
It returns an error:
Invalid input '|': expected ")", "{" or "$" (line 1, column 14 (offset: 13))
"MATCH(n:Movie|Person)"
(Neo4J 4.2.1)
02-11-2021 12:25 PM
i suspect it doesnt work as a result of a planning perspective.
Lets say you had
match (n:Movie|Person)
where n.title='The Matrix' or n.name='Tom Hanks'
return count(n);
now you have an index on :Movie(title) but not :Person(name) or what if you actually have an index on both :Movie(title) and or :Person(name) and also :Movie(name). Not sure how the planner would know how to plan that query.
i guess this is also similar to why the RDBMS world does not have 'select count(*) from Movies|Person'
All the sessions of the conference are now available online