postgresqlNewConnection(drv,...)中的错误:用户参数不能为NULL

时间:2018-08-21 14:12:29

标签: r postgresql

嘿,我试图将R连接到sql数据库,但是出现此错误。以下是代码。您知道如何修正错误吗?谢谢你一百万。

对不起,我无法在此处发布用户名和密码信息。但是我确定用户名和密码信息正确。

library(DBI)          
library(RPostgreSQL)
library(ggplot2)
usr <- {"######"}
pw <- {"######"}

dbs <- list()

dbs$r2day <-
  list(
    dbname = "gp_adw",
    host = "csia4gpm01",
    port = 5432,
    user = usr,
    password = pw
  )

sql_q <- function(query = "", db = "")
{
  # strip off db info from the dbs list
  db_info <- dbs[[db]]
  # specify driver type
  drv <- dbDriver("PostgreSQL")
  # connet db with db_info
  con <- dbConnect(
    drv,
    dbname = db_info$dbname,
    host = db_info$host,
    port = db_info$port,
    user = db_info$user,
    password = db_info$password
  )
  # submit query and bring result back in R
  df_postgres <- dbGetQuery(con, query)
  # disconnect the db and unload the driver
  dbDisconnect(con)
  dbUnloadDriver(drv)
  # return the r object
  df_postgres
}

alpha <- sql_q(query = "select * from comscore.mm200_pattern_parentage_222m limit 100", db = "gp_adw")

错误是

Error in postgresqlNewConnection(drv, ...) : user argument cannot be NULL

0 个答案:

没有答案