首页 > 解决方案 > 使用 Python 将数据帧保存到 Redshift 时出错

问题描述

我正在尝试将表从 Redshift 数据库复制到 Python 中的数据框,然后将其再次保存在 Redshift 中。

所以,第一步是有效的,但第二步我有一些问题。当我尝试保存具有 100 行的数据框时出现一些错误。

import pandas as pd
from sqlalchemy import create_engine

engine = create_engine("mssql+pyodbc://database")
df = pd.read_sql_query('select * from testing.table1 limit 100', engine)
df.to_sql(name='table2',schema='testing',con=engine,index=False,if_exists='append')

我收到了这个错误:

DBAPIError: (pyodbc.Error) ('HY000', '[HY000] [Amazon][ODBC] (10920) 已经下推的输入参数无法获取数据。

这很奇怪,因为当我尝试保存一个有 10 行的数据框时,根本没有错误。

标签: pythonpandassqlalchemyamazon-redshiftpandas-to-sql

解决方案


推荐阅读