python - Unique constraint violated oracle error. How can I get the insert statement of the violation in python?
问题描述
I have a code that looks like this:
sql1 = 'select column from table'
db1conn.execute(sql1)
results = db1conn.fetchall()
sql2 = 'insert into table(column) values(:1)'
db2conn.executemany(sql2,results)
sometimes for no known reason I get the 'Unique constraint violated' oracle error from python script. I would like python to tell me which insert statement failed when I did the executemany. how can I do this efficiently? I was thinking of preparing the sql2 statement myself using my own function. but that is probably not a good idea.
解决方案
Take a look at the batch errors example from the cx_Oracle repository. That shows you how you can figure out which row caused the problem and how to use the batch errors feature so the executemany() call doesn't fail, but you still get to figure out which rows caused problems and what those problems were.
推荐阅读
- node.js - JWT 认证失败
- javascript - Electron,如何使 100% 确定渲染器从主服务器接收消息?
- c# - 如何在 WPF 中的 ReactiveUI 中设置 ItemsSource 和源集合之间的双向绑定
- swift - UITextField 的 leftView 上的图像未呈现
- swagger - 无法解析 yaml 文件中 requestBody 中定义的参考组件架构
- python - 优化:根据日期将带有DatetimeIndex的pandas DataFrame拆分为列表
- javascript - 如何在 OnChangeText 中向我的组件 inputText 添加两个状态
- javascript - learnyounode 9#上这两种解决方案有什么区别?
- react-native - React Native 仅显示模式/屏幕一次
- matlab - 如何找到一个逻辑值来发现日期是否具有相同的月份和年份?