Fre*_*a K 3 postgresql r rpostgresql
我正在尝试使用RPostgreSQL和R v2.14.2将表读入R.
我的RPostgreSQL版本列为0.3-2,已于2012年5月16日下载.
我的DBI版本列为0.2-5,已于2012年5月16日下载.
我可以打开数据库,并列出表格.我要打开的表格显然存在,但是,当我尝试阅读它时,我收到一条错误消息.我不确定错误是在我的代码中还是在数据库的设置方式中.
library(RPostgreSQL)
# Loading required package: DBI
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, host = 'freda.freda.com', dbname = 'test', user = 'fredak', password = 'xxxx')
dbListTables(con)
# [1] "chemistry”
# [2] "ecog”
# [3] "hematology"
dbExistsTable(con, "ecog")
# [1] FALSE
MyTable <- dbReadTable(con, "ecog")
# Error in postgresqlExecStatement(conn, statement, ...) :
# RS-DBI driver: (could not Retrieve the result : ERROR: relation "ecog" does not exist
# LINE 1: SELECT * from "ecog"
# ^
# )
# Error in names(out) <- make.names(names(out), unique = TRUE) :
# attempt to set an attribute on NULL
# In addition: Warning message:
# In postgresqlQuickSQL(conn, statement, ...) :
# Could not create executeSELECT * from "ecog"
Run Code Online (Sandbox Code Playgroud)
Ser*_*hia 12
如果想要与命名模式中的表进行交互,请使用以下(非直观)语法:
dbExistsTable(con, c("schema_name", "table_name"))
[1] TRUE
Run Code Online (Sandbox Code Playgroud)
尽管dbListTables(con)
返回所有表名而没有关联的模式,但这仍然有效.