2016-11-16 6 views
1

私はRをpostgreSQLデータベースに接続しようとしています。彼は私が試みていることですR:RをpostgreSQLデータベースに接続する

require("RPostgreSQL") 

pw<- { 
    "password" 
} 

# loads the PostgreSQL driver 
drv <- dbDriver("PostgreSQL") 
# creates a connection to the postgres database 
# note that "con" will be used later in each connection to the database 
con <- dbConnect(drv, dbname = "DBname", 
       host = "localhost", port = 5432, 
       user = "user", password = pw) 
rm(pw) # removes the password 

# check for the test_table 
dbExistsTable(con, "test_table") 
# FALSE >>> Should be true 

なぜ私のデータベースに正しく接続されていないのか分かりません。私はターミナルとpgAdmin4でデータベースに接続できるので、データベースがコンピュータ上にあることを知っています。どんな助けでも大歓迎です。

おかげ

+0

かなり有効であるあなたはポート5436が必要なのでしょうか? – vagabond

+1

'dbListTables(con)' – vagabond

+0

のときに何が得られるのですか。接続が機能しているように見えます。なぜそれが私に偽の答えを与え続けているのか分かりません。私は質問をする前にまず質問を試みたはずです。助けてくれてありがとう。サイドノートで – erik12324

答えて

3

私はDBIとの組み合わせでRPostgresパッケージとのより良い成功を収めていると私はRPostgreSQLがちょうどしばらくの間、何も変更した後、月に新バージョンをリリースしていることを知っています。 RPostgres

## install.packages("devtools") 
#devtools::install_github("RcppCore/Rcpp") 
#devtools::install_github("rstats-db/DBI") 
#devtools::install_github("rstats-db/RPostgres") 

library(RPostgres) 
library(DBI) 

pw<- { 
    "password" 
} 

con <- dbConnect(RPostgres::Postgres() 
    , host='localhost' 
    , port='5432' 
    , dbname='DBname' 
    , user='user' 
    , password=pw) 


rm(pw) # removes the password 

dbExistsTable(con, "test_table") 
1
>install.packages("RPostgreSQL") 
>require("RPostgreSQL") 
#this completes installing packages 
#now start creating connection 
>con<-dbConnect(dbDriver("PostgreSQL"), dbname="dbname", host="localhost", port=5432, user="db_user",password="db_password") 
#this completes creating connection 
#get all the tables from connection 
>dbListTables(con) 
関連する問題