Reputation: 11
I am using py2neo to connect python to a neo4j database.Then I am trying to execute a query to set up a label name to some nodes, but the label name is a parameter. This is my code
for nodeID in nodesIDs:
nodes=nodesIDs[nodeID]
r=graph.cypher.execute("MATCH (d:node00) WHERE d.name in{x} SET d:{ID} RETURN d.name",{"x":nodes,"ID":nodeID})
print len(r)
but this give me an error said the "Invalid input '(': expected whitespace or a label name"
please advise
Upvotes: 1
Views: 253
Reputation: 8556
Let's look at the query you are executing:
MATCH (d:node00)
WHERE d.name IN {x}
SET d:{ID}
RETURN d.name
Where the parameter x
is presumably an array of strings, and the parameter ID
is a string.
Here are some points to consider:
SET d:{ID}
will not work. Instead, use string concatenation within your python script to include the label as part of the string query, not as a parameter: "...SET d:" + str(newLabel) + ...
x
is actually an array of strings and be sure you have proper spacing in the clause WHERE d.name IN {x}
(space between IN
and {x}
)Upvotes: 0
Reputation: 141
White space is significant in Cypher query. Make sure that your query actually runs in the Neo4j shell before throwing it into the Python wrapper.
Upvotes: 1