首页 > 解决方案 > postgresqlNewConnection(drv, ...) 中的错误:用户参数不能为 NULL

问题描述

嘿,我正在尝试将 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

标签: rpostgresql

解决方案


推荐阅读