sql save deletes the existing rows and them appends

Hi all,

I am trying to update rows from R to sql table. I am following below code for this. But the issue, when ever i run this, it delete the existing rows and then appends. Is there a way to only append the rows/

Example : In first instance, I am updating new rows (10) to sql table. At second instance, there are 90 rows, but since the below code deletes the existing rows, the final output is 90 rows in sql table. But actually, it should be 90+10 (100 rows). Is this possible to achieve?

sqlSave(conn, df, tablename = "sql_table", rownames = FALSE ,colnames = FALSE, append=TRUE)

Can you make a reprex ?

df is dataframe in R and sql_table is table in sql

df
COlA       COlB           COlC
1          dfg             jkl
2          fe              jkl
3          rfew            sdf

When I run below code , my sql table in sql has 3 rows (that is perfect)

sqlSave(conn, df, tablename = "sql_table", rownames = FALSE ,colnames = FALSE, append=TRUE)

But when I run the above code again, my sql table has only 3 rows since the old row are deleted. But I need to have 6 rows (3+3)

sqlSave(conn, df, tablename = "sql_table", rownames = FALSE ,colnames = FALSE, append=TRUE)

Vinay, I'm busy, so if you had a reprex I would look at your issue. Without a reprex I'm less likely to spend time. Good luck, I might check this later.

Sorry. Above is the reprex I thought you were expecting :slight_smile: Could you help me what else you need :slight_smile:

It should be a text of code I can simply copy from your post into a new rstudio session and expect to see the behaviour that you see.
That means libraries loaded. Objects defined etc.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.