python - 在 MS Access 中使用 to_sql(... , method='multi') 时出错
问题描述
我正在使用以下代码将数据插入 Microsoft Access 数据库:
test_data.to_sql('employee_table', cnxn, index=False, if_exists='append', chunksize=10, method='multi')
这给出了错误:
AttributeError: 'CompileError' object has no attribute 'orig'
仅使用以下即无method
选项时没有错误:
test_data.to_sql('employee_table', cnxn, index=False, if_exists='append', chunksize=10)
解决方案
您引用的错误消息是由原始错误引起的后续异常(在堆栈跟踪的早期):
sqlalchemy.exc.CompileError:具有当前数据库版本设置的“访问”方言不支持就地多行插入。
希望创建多行 INSERT 语句的method="multi"
选项,通常以“表值构造函数”的形式,例如,.to_sql()
INSERT INTO table1 (col1, col2) VALUES (1, 'foo'), (2, 'bar')
Access SQL 不支持这些。
如果一个普通的.to_sql()
(没有method=
)对于一个大的 DataFrame 来说太慢了,那么考虑在 wiki 中记录的替代方法:
推荐阅读
- audio - 为什么 librosa 加载会更改 flac 文件?
- crm - SLATE crm 集成 api
- php - 查询字符串参数键是否可以包含连字符 (-) 字符?
- javascript - 如何与使用 GM_openInTab 打开的选项卡的元素进行交互
- javascript - 从后端获取GET请求后如何告诉浏览器提示下载框?
- c# - c# 泛型集
按类型访问对象的实现 - python - Cannot Read Number using Pytesseract
- time - Microsoft Power BI - DAX 时间智能测量 - 更改上下文以反映适当的百分比变化;非 YTD 措施
- testcontainers - 在初始化脚本之前在 postgres 测试容器中创建一个文件夹
- reactjs - React Native 在不同的导出函数中使用帮助 api 文件中的上下文