Search code examples
pythonneo4jpy2neo

How to use parametrized query to extract node property in py2neo


I have a NEO4J database and i need to pass parametric query to retrieve properties of a node using Py2neo library


Solution

  • It's quite simple actually. Let's take an example that you have a node property Name on which you need to extract the data.

    In below example we took a key 'Node_Name' and put a where clause on Name property. While executing the query we passed the condition value (xyz) in parameters clause matching to that key. You can use multiple key by comma-separation in the parameters clause.

    query = "Match (n:P)-[:next]->(P) where n.Name={ Node_Name } return P.Name"
    result = graph.cypher.execute(query, parameters={"Node_Name": "xyz"})
    

    Let me know if this address your problem.