我实际上是在尝试使用pyorient进行sql-batch插入。
我实际上在Edge(in,out)上有唯一索引以防止重复,因为我找不到UPSERT Edge的方法。
session_orientdb.command("CREATE INDEX indexRegroupe ON Regroupe (out, in) UNIQUE")
如果我每100行发送一次命令,并且如果一行因为orientdb找到duplicateIndex(in,out)而抛出一个预期,那么整个100行都不会插入。
所以这是我的循环:
i = 0
cmd = "BEGIN;"
# Loop untill receiving the "poison pill" item (meaning : no more element to read)
poison_pill = False
while not(poison_pill):
queries = p_queue.get()
# Manage poison pill
if queries is None:
poison_pill = True
p_queue.task_done()
cmd += "commit;"
session_orientdb.batch(cmd)
else:
for query in queries:
i += 1
cmd += query + ";"
if (i > 100):
i = 0
cmd += "COMMIT retry 20;"
try:
session_orientdb.batch(cmd)
except Exception as e:
print (e)
cmd = "BEGIN;"
查询类似于:
[
'UPDATE Expression SET libelle = "internat fille" UPSERT WHERE libelle = "internat fille";',
'CREATE EDGE Regroupe FROM (SELECT FROM Ontologie WHERE id = "40") to (SELECT FROM Expression WHERE libelle = "internat fille") set score=8;',
'UPDATE Cri SET id = "INTERNAT", libelle = "internat" UPSERT WHERE id = "INTERNAT";',
'CREATE EDGE Identifie FROM (SELECT FROM Expression WHERE libelle = "internat fille") to (SELECT FROM Cri WHERE id = "INTERNAT");'
]
我该怎么办?
答案 0 :(得分:2)
你应该使用条件if
实施例
begin
let a= select from Regroupe where out=#9:0 and in=#10:0
if($a.size()>0){
// edge exists so do other query
}
return $a
希望它有所帮助。