gpt4 book ai didi

mysql - 通过 R 更新 MySql 表的问题

转载 作者:行者123 更新时间:2023-11-29 16:53:10 26 4
gpt4 key购买 nike

给定的代码有什么问题..

dbExecute(con_pratham,paste("Update unit_dummy  set isDeleted=",paste(data_to_update$IsDeleted)," , status =", paste0(data_to_update$status), "where UnitId =",paste(data_to_update$UnitId)))

它应该根据其 UnitId 更新两列 “status”IsDeleted。这里“data_to_update”是具有 500 个观察值的数据帧。这些行中的每一行都有“Status”和“IsDeleted”以及“UnitId”。当我打印上面的代码时,它完美地生成了大约 500 个与此类似的更新 SQL 语法..

[476] "Update unit_dummy  set isDeleted= 0  , status = 1 where UnitId = 56061"
[477] "Update unit_dummy set isDeleted= 0 , status = 1 where UnitId = 56063"
[478] "Update unit_dummy set isDeleted= 0 , status = 1 where UnitId = 56065"
[479] "Update unit_dummy set isDeleted= 1 , status = 0 where UnitId = 56069"
[480] "Update unit_dummy set isDeleted= 1 , status = 0 where UnitId = 56070"
[481] "Update unit_dummy set isDeleted= 1 , status = 1 where UnitId = 56095"
[482] "Update unit_dummy set isDeleted= 0 , status = 1 where UnitId = 56100"
[483] "Update unit_dummy set isDeleted= 1 , status = 0 where UnitId = 56132"

当我复制任何这些 sql 行并在服务器上运行时,它工作正常,但不能通过 R。请指导我这一点..

最佳答案

我会尝试这样的事情:

sqls <- paste("Update unit_dummy  set isDeleted=",paste(data_to_update$IsDeleted)," , status =", 
paste0(data_to_update$status), "where UnitId =",paste(data_to_update$UnitId))


for (sql in sqls){
dbExecute(con_pratham, sql)
}

关于mysql - 通过 R 更新 MySql 表的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52707543/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com