1

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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:

  1. Node labels cannot be parameterized in a Cypher query. Therefore the clause 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) + ...
  2. Make sure the parameter 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})
  3. Finally, you might want to reconsider how you are using labels. It looks like you are treating the label as an ID that identifies an individual node. Labels should be used to identify the type or "class" of Nodes, such as "Person" or "Event", etc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.