I have a table name stock with (item,date) as index in Postgres database which record monthly record. Then I have pandas dataframe name stock_df which calculate monthly stock. Now I need to append that stock_df in table stock in postgres in such way that.
If stock_df has same item and same date like in stock table, it should update table and if it is new record it should be append.
I tried this:-
stock_df.to_sql(name="stock", con=conn_postgres, if_exists='update', schema='arpan', index=False)
But this code check all the column and if it is dublicate it update or append the table which is different from what I desire My requirement is:- If stock_df item and date match the index of stock(item,date) then it should update data and if it didn't then it should append.