【问题标题】:Unable to pass strings in dbgetquery in r. it says invalid identifier无法在 r 中的 dbgetquery 中传递字符串。它说无效的标识符
【发布时间】:2021-09-14 14:19:18
【问题描述】:

当我运行它时,它会显示它的无效标识符“RTX”。

 gf<-"cyberpunk"
 #input$rat gives a value of string "RTX"
delete<-paste("select * from games where name = ",gf," and graphics = ",input$rat, sep="")
      
      yx<-dbGetQuery(ValidateUser,delete)
      print(yx)

【问题讨论】:

    标签: sql r sqlite


    【解决方案1】:

    我们可能会使用glue

    glue::glue("select * from games where name = '{gf}' and graphics = '{input$rat}'")
    

    【讨论】:

      【解决方案2】:

      您需要在所有character 字段的查询中包含引号,并且paste0 而不是paste 将避免出现意外空格:

      delete <- paste0("select * from games where name = '",gf,"' and graphics = '",input$rat,"'")
      
      delete
      [1] "select * from games where name = 'cyberpunk' and graphics = 'RTX'"
      

      【讨论】:

        猜你喜欢
        • 2013-01-28
        • 2017-06-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-13
        • 2021-08-21
        • 2018-10-03
        • 1970-01-01
        相关资源
        最近更新 更多