在使用sqlalchemy作为池框架处理sybase时,我将问题简化为pandas to_sql,在#tmp周围添加双引号
Code :
def get_data_with_tmp():
engine = get_connection("sybase")
with engine.connect() as conn:
df = pd.DataFrame({'alias_id': ['345402KP5', '3454014R1']})
df.to_sql(name='#tmp', con=conn, schema=None, if_exists='append', index=False)
df = pd.read_sql_query("SELECT alias_id from #tmp", con=conn)
Error:
statement = '\nCREATE TABLE "#tmp" (\n\talias_id TEXT NULL\n)\n\n' E pyodbc.ProgrammingError: ('42000', "[42000] [SAP][ASE ODBC Driver][Adaptive Server Enterprise]Incorrect syntax near '('.\n (102) (SQLExecDirectW)")
当我删除#tmp周围的双引号时,它在sybase中运行良好。 同样,这段代码在SqlServer中运行良好,无需任何修改
你知道如何解决这个问题吗? 我也欢迎其他建议。 请注意,我确实有一个绕过数据帧和逐行插入的解决方案,但我更喜欢使用数据帧的好东西,如批处理、批插入等
此错误已在外部sybase方言中修复
https://github.com/gordthompson/sqlalchemy-sybase
具体地
https://github.com/gordthompson/sqlalchemy-sybase/releases/tag/1.0.1
相关问题 更多 >
编程相关推荐