cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Help: Pass Python parameter into Cypher statement syntax

FourMoBro
Node Clone

So I have a working Cypher query within python which can query my Neo4j database and return a result when a property key value is hardcoded. It looks like this:

piq = """MATCH (p:Person {bid: '123456789'}), blah blah blah """
with driver.session() as session:
profile_info = session.run(piq).values()

What I want to do is replace that string value with a parameter:
bid = 123456789
so the query text becomes something like
piq = """MATCH (p:Person {bid: bid}), blah blah blah """

I have tried $bid, {bid}, and also specifying things in the session.run area but just can't seem to find the correct syntax.

Any help, would be appreciated, and I would rather not try to install py2neo as I have had enough of the driver conflicts.

3 REPLIES 3

Hello @FourMoBro

with ctx.session() as ses:
    profile_info = ses.run("MATCH (p:Person {bid: $bid}), blah blah blah ", bid=bid)

Regards,
Cobra

Thanks @Cobra. I was close, but I also had another error in my code.
I also needed to have bid=str(123456789)

I love how fast this community responds!

Oh yeah sorry, I didn't see it was a string