I'm using pandas df.to_sql to inserting rows to postgresql database.
df.to_sql('example_table', engine, if_exists='replace',index=False)
example_table has 3 columns :'id' ,'name' ,'datetime'
I want to add a checking logic before inserting ,that if the datetime is already exits ,then replace or update the exiting row.
Is there something like:
df.to_sql('example_table', engine, if_ datetime_exists='replace',index=False)
There is no if_exist sql function. Try this instead:
This will insert datetime in db if not already there also will update existing rows in case of missing datetime.