我在 qry2 中強制出錯,以便 a 可以運行 qry3,假設它可以回滾到 save_1 但它沒有。有什么收獲嗎?使用 PostgreSql 14.2
qry1 = ('begin;'
'savepoint save_1;'
'delete from ntnb_cup;')
qry2 = ...
# Force error
qry3 = 'rollback to save_1;'
try:
cursor = conn.cursor()
cursor.execute(qry1)
conn.commit()
except Exception as err:
cursor.close()
conn.close()
exit()
try:
cursor.execute(qry2)
conn.commit()
except Exception as err:
cursor.execute(qry3)
conn.commit()
finally:
cursor.close()
conn.close()
uj5u.com熱心網友回復:
try:
cursor = conn.cursor()
cursor.execute(qry1)
conn.commit()
一旦你承諾,你就承諾了。要保留稍后回滾到保存點的選項,請不要在此處提交。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/448467.html
上一篇:處理函式數值變數上的空值''
