0

I need to use pandas df.to_sql without auto commit at the end. Is there a way to do that?

Thanks

ranthero
  • 92
  • 7

1 Answers1

2

Are you using SQLAlchemy? If so, SQLAlchemy will always commit automatically (see e.g. here) You could however use the engine.begin context manager to roll back any commits upon failure:

with engine.begin() as conn:
    df.to_sql(name= 'test1',schema='test', con=conn)
Christian Karcher
  • 2,533
  • 1
  • 12
  • 17