How to prevent pandas dataframe from adding double quotes around #tmp when using sqlalchemy and sybase?

天大地大妈咪最大 提交于 2021-02-05 07:43:49

问题


I have reduced the issue to pandas to_sql adding double quotes around #tmp when dealing with sybase using sqlalchemy as the pooling framework.

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)")

When I remove the double quotes around #tmp it works fine in sybase. Also, this same code works fine in SqlServer without any modifications.

Any idea how to solve this issue? I would welcome alternative suggestions as well. Note that I do have a workaround of looping through the dataframe and inserting row by row, but would really prefer a solution that makes use of dataframe good stuff like batching, batch insert etc.


回答1:


This bug has been fixed in the external sybase dialect

https://github.com/gordthompson/sqlalchemy-sybase

specifically

https://github.com/gordthompson/sqlalchemy-sybase/releases/tag/1.0.1



来源:https://stackoverflow.com/questions/61917192/how-to-prevent-pandas-dataframe-from-adding-double-quotes-around-tmp-when-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!