How to introduce parameters in a cypher query?
<p>I have this cypher query in a Python program:</p>

<pre><code>prevNode = graph_db.data("OPTIONAL MATCH (n:Node) WHERE n.property = {param} RETURN n")
</code></pre>

<p>The line of code above gives the next error:
'py2neo.database.status.ClientError: Expected a parameter named param'</p>

<p>param is well defined at this point of the program because I print it a line before executing the query.</p>

<p>I have tried to put the value in the query instead of the parameter, like this:</p>

<pre><code>prevNode = graph_db.data("OPTIONAL MATCH (n:Node) WHERE n.property = '1234' RETURN n")
</code></pre>

<p>And worked well.</p>

<p>Does anyone knows where is the mistake?
Thanks in advanced. </p>

<p>You didn't pass any substitution variables into the function.</p>

<pre><code>graph_db.data("OPTIONAL MATCH (n:Node) WHERE n.property = {param} RETURN n", param='1234')
</code></pre>

<p>You can also explicitly pass in the <code>locals()</code> dictionary; this will use any local variables you have defined of the appropriate names:</p>

<pre><code>graph_db.data("OPTIONAL MATCH (n:Node) WHERE n.property = {param} RETURN n", **locals())
</code></pre>

python neo4j cypher py2neo