'How to change SET column name with variable in Postgresql through R?

I have a analytic table in Postgresql which consists of several columns namely, unbonding, clogging and dirty. this column contains numbers.

I want to update a value +1 in the column according to the "issue" selected by the user. For example "clogging".

issue="clogging"
currentdata <- dbGetQuery(con,paste0("SELECT DISTINCT *
                                                FROM analytic
                                                ORDER BY analytic.id DESC
                                                FETCH FIRST 1 ROWS ONLY;"))
issueval <- currentdata[[issue]]

sql <- sqlInterpolate(con, 
                      "UPDATE analytic 
                      SET issue = ?val
                      where id = ?code",
                      code = "ID111",
                      val = issueval+1
)
dbSendQuery(con,sql)

How can I change the SET "column name" according to the issue the user has selected?

thankyou



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source