I'm doing a Neo4j hands-on exercise, following along to a UCSD video. I'm cutting and pasting the script provided for the exercises. I've just run into a problem with the provided script for a graph not containing the immediate neighborhood of a specified node:
match (d {Name:'D'})-[:TO]-(b)
with collect(distinct b.Name) as neighbors
match (n)-[r:TO]->(m)
where
not (n.Name in (neighbors+'D'))
and
not (m.Name in (neighbors+'D'))
return n, r, m;
match (d {Name:'D'})-[:TO]-(b)-[:TO]->(leaf)
where not((leaf)-->())
return (leaf);
match (d {Name:'D'})-[:TO]-(b)<-[:TO]-(root)
where not((root)<--())
return (root)
This returns:
Expected exactly one statement per query but got: 3
When I run the first 8 lines, Neo4j returns the graph, with expected nodes and edges. But when I add the subsequent queries, the error msgs start popping up.
If you're using Neo4j Browser to run those CYPHERs, make sure multi statement query editor is enabled. You can enable it in Browser Settings by click the checkbox.
Neo4j Browser can run only one query at time. You are trying to run 3:
Query 1:
match (d {Name:'D'})-[:TO]-(b)
with collect(distinct b.Name) as neighbors
match (n)-[r:TO]->(m)
where
not (n.Name in (neighbors+'D'))
and
not (m.Name in (neighbors+'D'))
return n, r, m;
Query 2
match (d {Name:'D'})-[:TO]-(b)-[:TO]->(leaf)
where not((leaf)-->())
return (leaf);
Query 3:
match (d {Name:'D'})-[:TO]-(b)<-[:TO]-(root)
where not((root)<--())
return (root)
You must copy, paste and run these 3 queries separately.
Here is an open issue in the Neo4j Browser Github Repo about supporting multiple Cypher statements at a time in the browser, but this is specifically for statements that don't return any data.
A quick solution which worked for me (also mentioned at the neo4j.com/graphacademy/online-training/) when playing with an online sandbox:
Before you start
Enable multi-statement query editor
Click the Browser Settings button in the lower left side of Neo4j Browser
Make sure that the Enable multi statement query editor checkbox is selected:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With