Search code examples
neo4jpy2neo

How to introduce multiple variables in graph.run() through python?


hi I am sort of new to py2neo which is supposed to be supported by neo4j community

I just wanted to do a

graph.run("MATCH (a) - [:{x}]-> (b) WHERE b.name = {y} RETURN b.name " ).to_table()

but wanted to use two variables x,y in run() which I could pass onto using as a function parameter in python, wasn't able to find out any sort of documentation on this. Would really appreciate some direction or help


Solution

  • Cypher doesn't accept relationship types as query parameters.

    You can not pass x as a parameter here, I would suggest you create a query string in python with x as a parameter and then pass y as a parameter in a run().

    Something like:

    query_string = "MATCH (a) - [:%s]-> (b) WHERE b.name = {y} RETURN b.name " % (x)
    

    And pass y as a parameter to run() method:

    graph.run(query_string, {"y":y}).to_table()