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.

Run cypher query in python doesn't working

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
2 REPLIES 2

Try using '$' for your parameters. I think '%' is an older syntax that is no longer used.

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/