I have a table in PostgreSQL database, hosted on Azure cloud. In this table, I have created foreign key constraints on multiiple columns.
I have a script in R which tries to push the contents of a dataframe in the above table in PostgreSQL database. Below given code is used to do the same in R :
DBI::dbWriteTable(db_con,
table_name,
dataframe_name,
row.names = F,
overwrite = T)
When I try to execute the above code, data from dataframe in R is pushed to DB in Azure but all the foreign key constraints are lost.
I am also aware of the fact that dbWriteTable drops the table completely when overwrite=TRUE. And this dropping the table breaks the foreign key constraint.
Is there maybe a way to do this, like overwriting the data from dataframe in R to table in DB in Azure ? Can someone please help me to do this ?
Is there also a possibility that I would be able to do this using combination of R and SQL ? Because in R, as per my knowledge, SQL queries can be written using sqldf package.
Any leads/hints in regards to above issue will be very helpful.