I have a Shiny app with which the user selects a table in a SQL database and then selects some columns of this table. Then the app runs this function to get the table:
selectAllGetQuery <- function(conn, columns, table){
columns <- toString(sprintf("[%s]", columns))
query <- sprintf("select %s from %s", columns, table)
print(columns) # ok
print(query) # ok
dbGetQuery(conn, query)
}
One table has a column named ACT_TEMP_°C_. When I select it, the dbGetQuery statement fails: Invalid column name 'ACT_TEMP_°C_'. However, as you can see, I included print(columns) and print(query) in the function, and these statements correctly print ACT_TEMP_°C_ in the R console. So I'm really lost. The function receives the correct name but the name changes to the wrong name in dbGetQuery.