I have a variable name="Rahul" and, I want to pass this variable to cypher query in Py2neo in the following manner:
line=session.execute("MATCH (person)WHERE person.name=name RETURN person")
but i am getting an error -
"py2neo.cypher.InvalidSyntax: name not defined (line 1, column 33)"
how to pass the variable in py2neo
If name
is a parameter you need to enclose it in curly braces. Your query should look something like
MATCH (person) WHERE person.name = {name} RETURN person
Your Python code may look along the following lines
graph_db = neo4j.GraphDatabaseService()
qs = 'MATCH (person) WHERE person.name = {name} RETURN person'
query = neo4j.CypherQuery(graph_db, qs)
results = query.execute(name='Rahul')
print results
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