从R中向数据库插入值:sqlQuery中的错误(con,req):第一个参数不是一个开放的RODBC通道

时间:2015-01-29 13:57:05

标签: sql r insert insert-into

查询postgresql数据库:

代码:

drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname="BDDMeteo", user=user, password="zina",host='localhost', port='5432')
#selection
cluster1=dbGetQuery(con,"select station.lon,station.lat from station where station.cluster=1")  
#insertion
req=paste("INSERT INTO important (num_cluster,type,indicateur_imp) VALUES (1,'temperature',2)")
resultat=sqlQuery(con,req)

如何选择好,但是对于插入,他向我发送了以下错误:

Error in sqlQuery(con, req) : first argument is not an open RODBC channel

请帮忙吗?

1 个答案:

答案 0 :(得分:1)

您在VALUES Clause

之后错过了括号
req=paste("INSERT INTO Important (Num_cluster,Type,Indicateur_impt) VALUES (1,'temperature','Imp1')")
resultat=sqlQuery(con,req)