Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-08-2019 09:29 AM
Since I have read a very nice topic from Michael Hunger, I was trying to make it works with py2neo.
Then I tried to set the parametes by sending a Cypher statement as followed:
cypher = ':param batch:[{name:"Alice",age:32},{name:"Bob",age:42}]'
graph.run(cypher)
This will cause a error as followed:
py2neo.database.ClientError: SyntaxError: Invalid input ':': expected <init> (line 1, column 1 (offset: 0))
But if just pasted the cypher onto the neo4j browser, it will just set the parameters successfully.
Can anyone tell me what is wrong with that and is there any other ways to make the insertion more efficient and fast in python?
By the way, the neo4j server reads data from mysql dynamically in real time, so that I can keep both databases' data synchronous.
Thanks!
05-08-2019 12:29 PM
this should work:
':param batch=> [{name:"Alice",age:32},{name:"Bob",age:42}]'
05-08-2019 07:24 PM
Thanks, but I tried this way and it not works..
05-09-2019 10:22 AM
I asked this a while back: How does Py2Neo use parameters to make repeat queries faster?
try:
cypher = 'merge (u:User {name:{name1},age:{age1}}) merge (u2:User {name:{name2},age:{age2}})'
graph.run(cypher, {"name1":"Alice","name2":"Bob","age1":32,"age2":42})
05-09-2019 07:25 PM
Hi, this did work, here is my code:
batch = [{name:"Alice",age:32},{name:"Bob",age:42}]
graph.run(query, rel_batch)
Thanks
05-13-2019 05:58 AM
Your original syntax uses a client command, which exists only in applications such as the browser and the Cypher shell; these commands are not part of Cypher itself. The final code you posted it indeed the correct way to do this: passing the parameters along with the Cypher query string as a second argument.
05-15-2019 02:43 AM
I see the difference between browser and Cypher itself. Thanks sooo much!
07-28-2019 01:25 PM
@mading0817
batch = [{name:"Alice",age:32},{name:"Bob",age:42}]
graph.run(query, rel_batch)
Hello, can you explain, what exactly does query and rel_batch mean? Can you give an example?
07-29-2019 12:48 AM
Hi, Im sorry there is a mistake, it shoule be:
batch = [{name:"Alice",age:32},{name:"Bob",age:42}]
query = """
UNWIND {{batch}} as row
.....
your query-
.....
""".format(batch=batch)graph.run(query, batch=batch)
All the sessions of the conference are now available online