Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-10-2022 03:47 AM
Hi,
I just run to make the relationship between two nodes in python.
Run the raw cypher query with tx.
When I run the query in neo4j Desktop It works, But doesn't work in python code.
Well, it looks like work, but the database doesn't update.
Any comments would be appreciated. Thanks
poiName = poiProperty['poiName']
with self.driver.session(database="hpg01") as session:
tx = session.begin_transaction()
stmt = '''
MATCH (poi:Poi {poiName: "%s", poiId : %s})
MATCH (mbti:MBTI {name: "%s"})
MERGE (poi)-[:MBTI_IS]->(mbti)
RETURN (poi)-[:MBTI_IS]->(mbti)
'''%(poiName,int(poiId), mbti)
result = tx.run(stmt)
print("result: ", result.single()[0])
return result
01-10-2022 03:34 PM
Try using '$' for your parameters. I think '%' is an older syntax that is no longer used.
01-10-2022 09:15 PM
Hi @gotnwjd40
I think the basic code looks like this.
tx.run("MATCH (poi:Poi {poiName: $poiName, poiId : $poiId}) "
"MATCH (mbti:MBTI {name: $name}) "
"MERGE (poi)-[:MBTI_IS]->(mbti) "
"RETURN (poi)-[:MBTI_IS]->(mbti)",
poiName=poiName, poiId=poiId, name=name)
You can find the good sample codes here.
https://neo4j.com/docs/api/python-driver/current/
All the sessions of the conference are now available online