Home > Back-end >  Unable to pass strings in dbgetquery in r. it says invalid identifier
Unable to pass strings in dbgetquery in r. it says invalid identifier

Time:09-17

When i run this, it says its invalid identifier "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)

CodePudding user response:

You need to include quotes in the query for all character fields, and paste0 instead of paste will avoid unexpected spaces :

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

delete
[1] "select * from games where name = 'cyberpunk' and graphics = 'RTX'"

CodePudding user response:

We may use glue

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