批量插入异常
Exception with batch insert
我实际上正在尝试使用 sql-批量插入 pyorient。
我实际上在 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");'
]
我能做什么?
你应该使用条件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
希望对您有所帮助。
我实际上正在尝试使用 sql-批量插入 pyorient。
我实际上在 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");'
]
我能做什么?
你应该使用条件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
希望对您有所帮助。