Home > OS >  Data Frame to_sql without waiting for execution?
Data Frame to_sql without waiting for execution?

Time:05-01

I was looking everywhere here, I can not find a way to perform a simple single line insert without waiting for respond, just keep executing next line :

    engine = sqlalchemy.create_engine('postgresql psycopg2://'   username   ':'   password   '@/'   database   "?host="   path)

    df.to_sql('queries', engine, if_exists='append', index=False)

This runs on a server to save some analytics to Postgresql, and i don't want to wait for respond, I also don't care if it failed here and there.

It is super important to me, to keep executing right after, and spend no time on this.

How to do this ?

CodePudding user response:

From the documentation df.to_sql() does not support what you want. But there are some workarounds you can do:

  1. Create a function that uses threading to insert this df to your db. Check this answer.
  2. You can use async calls and sqlalchemy but you would need to map this dataframe to an object or something that sqlalchemy can work with.
  • Related