Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass parameter to cypher query in py2neo

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

like image 499
Saubhagya Jena Avatar asked Feb 13 '23 11:02

Saubhagya Jena


1 Answers

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
like image 94
stephenmuss Avatar answered Feb 14 '23 23:02

stephenmuss