I have been trying to use the merge method to create a node using the Py2Neo driver but am having issues.
I try tx.merge(a,"Person",('name','age'))
but get the error: TypeError: tuple
In the merge documentation: here it says "Note that multiple property keys may be specified by using a tuple." Am I missing something simple?
I've been having the same issue lately, and after reading through the source code provided in the documentation, I've come to the conclusion that the py2neo is wrong with it says that "multiple keys may be specified by using a tuple" as no matter which merge()
you call (mostly because they're almost the same, except Graph.merge
uses Transaction
's autocommit value) it only allows 1 key and doesn't like the tuple type.
As an alternative, you can use a py2neo function that directly executes a Cypher MERGE
query to include whatever nodes you're trying to create/merge (ex. Graph.run("MERGE (:Node {...})")
). Unfortunately this doesn't really solve the issue, but this might not be in our hands.
Might be an issue with the arguments to the merge function. Perhaps try:
tx.merge(a, primary_label='Person', primary_key=('name', 'age'))
Also note there are two different methods for merge
functions in the documentation. See the difference between these two links:
http://py2neo.org/v4/database.html#py2neo.database.Graph.merge http://py2neo.org/v4/database.html#py2neo.database.Transaction.merge
I had similar problem in different context; I solved with..
a = Node("Person", name, age)
a.__primarylabel__ = "Person"
a.__primarykey__ = "name"
#a.__primarykey__ = "age"
tx.merge(a) # used graph.merge(a)
Looks like it doesn't work with multiple keys but just one works like this:
topic = Node("Topic",
cname=cname,
name=name
)
graph.merge(
topic, "Topic", "name"
)
where name is the key
to merge on.
v4 docs https://py2neo.org/v4/database.html?highlight=merge#py2neo.database.Graph.merge
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.