Sqldf R Update Function Language

I have a problem with SQLdf. Although I try to update the table, it always gives NULL as output. I am doing red things about this problem, but I cannot figure out how to solve it. My code is:

fn$sqldf("update cons set V1='%$numbernew%' where V1=$'contact'")

But after I checked it to see if something had changed, they were all the same as in the beginning. Any ideas will help.

+4
source share
1 answer

As Goran noted in a comment, this question is a frequently asked sqldf. Actually this is sqldf FAQ # 8 .

, , , . , $'contract' '$contract', contract, .

# set up test data for reproduciblity
con <- data.frame(V1 = c("a", "b", "c"))
contract <- "a"
numbernew <- "x"

, , :

sql1 <- fn$identity("update con set V1 ='%$numbernew%' where V1 = '$contract' ")
sql2 <- "select * from main.con"
sqldf(c(sql1, sql2))

:

   V1
1 %x%
2   b
3   c

:

sqldf() # start a sequence of SQL statements

fn$sqldf("update con set V1 ='%$numbernew%' where V1 = '$contract' ")
ans <- sqldf("select * from main.con")

sqldf() # SQL statements finished
+6

All Articles