我使用以下代碼將資料插入到 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)
uj5u.com熱心網友回復:
您參考的錯誤訊息是由原始錯誤(堆疊跟蹤中的早期)引起的后續例外:
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 中記錄的替代方法:
https://github.com/gordthompson/sqlalchemy-access/wiki/[pandas]-faster-alternative-to-.to_sql()-for-large-uploads
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/314228.html
標籤:Python 熊猫 ms-access sqlalchemy sqlalchemy 访问
