Reputation: 4143
Taking my first steps in Neo4J - there's something I don't quite get (perhaps related to syntax)
Why does this returns results
MATCH (d:People)-[HAS_VEHICLE*]->(v:Vehicle) return d, v
while this doesn't return any results
MATCH (d:People)-[r:HAS_VEHICLE*]->(v:Vehicle) return d, v
The difference between them is the introduction of the relationship variable - but why would it affect whether the query returns results or no results at all?
Upvotes: 0
Views: 133
Reputation: 67019
Actually, the difference between the 2 queries is that the first query does not specify a relationship type. Instead, the first query specifies HAS_VEHICLE
as an identifier.
Relationship types must be preceded by a colon. So, your first query should have been:
MATCH (d:People)-[:HAS_VEHICLE*]->(v:Vehicle) return d, v
[EDITED]
The above query should also return no results, which means that there are no paths in your DB that match the pattern specified. For example, to match the above pattern, all relationships have to be of the HAS_VEHICLE
type.
You can modify the query to not require the HAS_VEHICLE
type, and to return the actual relationship types along the paths that match the resulting new pattern:
MATCH (d:People)-[rels*]->(v:Vehicle)
RETURN d, EXTRACT(r IN rels | TYPE(r)) AS types, v;
Upvotes: 4