Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j: Expected exactly one statement per query but got: 3

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.

like image 889
James_Pineda Avatar asked Dec 16 '17 20:12

James_Pineda


3 Answers

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. enter image description here

like image 164
ShawnZhu Avatar answered Oct 16 '22 01:10

ShawnZhu


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.

like image 36
Bruno Peres Avatar answered Oct 16 '22 00:10

Bruno Peres


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

  1. Click the Browser Settings button in the lower left side of Neo4j Browser

    settings icon

  2. Make sure that the Enable multi statement query editor checkbox is selected:

    setting option image

like image 3
tgogos Avatar answered Oct 16 '22 01:10

tgogos