我有一个data.frame
存储在SQL
数据库中的,用包的dbWriteTable
功能创建的R
sqldf
。
data.frame
我想知道是否有一种方法可以在此 SQL 数据库中按名称获取特定列。
对于按名称获取行,此代码有效:
#let's say the row names I want to select from the data.frame are in a vector called selected_row_names, where the data.frame is called df and the SQL database is called db
query_text <- paste("('",paste(selected_row_names,collapse="', '"),"')",sep="")
query_expression_text <- paste("select * from ",df," where row_names in ",query_text," order by row_names",sep="")
selected_df = dbGetQuery(db, query_expression_text)
我的问题是按名称选择列是否有任何等价物?
如果我尝试这段代码,我选择的列名是:“col-1T-A_m1”和“col-1T-A_m2”:
query_string <- paste("select col-1T-A_m1, col-1T-A_m1 from ", df, sep="")
selected_df <- dbGetQuery(db, query_string)
我收到此错误消息:
Error in sqliteSendQuery(con, statement, bind.data) : error in statement: unrecognized token: "1T".