简体   繁体   中英

"The name of the object to be created is identical to the existing name" in IBM DB2 with pandas.to_sql if_exists='append'

Please, help with this problem. sqlalchemy-1.4.31 pandas-1.4.0 Python 3.6.8

engine = create_engine(ConfigDbDb2.sqlalchemy_engine_c_string, )
chumks = pd.read_sql_query(get_goods, engine, chunksize=chunksize)

for i, chunk in enumerate(chumks):
    print(i)
    chunk['predicted'] = chunk['name'].progress_apply(my_function)
    chunk.to_sql(table_name, engine, if_exists='append', index=False, dtype=dtype_good_test)

After first writing i have

(ibm_db_dbi.ProgrammingError) ibm_db_dbi::ProgrammingError: Statement Execute Failed: [IBM][CLI Driver][DB2/LINUXX8664] SQL0601N The name of the object to be created is identical to the existing name

Also, for some reason, sqlalchemy + pandas ignore schema parametr in connection string. So you shoud defin it directly in to_sql statement of pandas dataframe like
chunk.to_sql(table_name, engine, schema = 'MY_SCHEMA', if_exists='append', index=False, dtype=dtype_good_test)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM