4

This is a new one, and I have not found any mentions of this on other stackoverflow sites.

So I am programming in R and using the RPostgreSQL package to access a Postgres 9.1.5 database. So I created the connection to the database as I would normally do it, and now I am getting a strange error.

db.conn = function(){

  ## This function creates a connection to the database. Subsequent
  ## functions that access the db will go through this function.
  drv = dbDriver("PostgreSQL")
  con = dbConnect(drv, user = "user", password = "password", dbname = "dbname", host = "localhost", port = 5432)
  return(con)
}

so when I create an object:

testdb = db.conn()

The object seems to get created, but when I type

testdb

Error in function (classes, fdef, mtable)  : 
  unable to find an inherited method for function "show", for signature "PostgreSQLConnection"

I have never seen this error before. Any suggestions on where it might be coming from? Any help would be appreciated.

Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
krishnab
  • 9,270
  • 12
  • 66
  • 123

3 Answers3

2

Please do not cross-post. I just replied on the RPostgreSQL list too, saying that this works just fine for me:

R> library(RPostgreSQL)
Loading required package: DBI
R> drv <- dbDriver("PostgreSQL") 
R> con <- dbConnect(drv, user = "edd", password = ".....", dbname = "......",
+                   host = "localhost", port = 5432)
R> con
<PostgreSQLConnection:(21267,0)> 
R> 
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thanks for your help Dirk. Hmm, I am still getting the error, but it seems like the connection object is working fine. I am wondering if it might have to do with my version of Postgresql? But anyway, it seems like this is not an issue now. Thanks again. – krishnab Oct 02 '12 at 14:49
  • I'm having the same issue, and adding the parameters you mention does nothing for me. con <- dbConnect(dbDriver('PostgreSQL'), db = '....', user = 'SYSTEM', password='....', host='localhost', port='5432') I still get the same error stated by @krishnab above. The connection was working fine until I started creating users to handle connections from Jenkins correctly. – JAponte Aug 15 '13 at 13:12
  • ok... for some reason, I cleaned up my workspace, redefined con, and it now prints just fine. – JAponte Aug 15 '13 at 13:19
  • Good to know -- I was just about to suggest that you post a _reproducible_ example on the mailing list. – Dirk Eddelbuettel Aug 15 '13 at 13:20
  • `dbIsValid(con)` returns an error. Is that expected? – Brian D Aug 12 '20 at 22:03
1

In case this is helpful for others, I received a similar error:

"unable to find an inherited method for function dbIsValid for signature "PostgreSQLConnection"

This happened when I inadvertently forgot to assign the result of my dbConnect call to a connection object.

So this did not work:

dbConnect(...)

but this did:

con <- dbConnect(...)

Rao
  • 20,781
  • 11
  • 57
  • 77
AngieH
  • 11
  • 1
1

I had the same problem as yours.My solution is to remove the "DBI" package and re-install it. It works for me. But it might not work for you. you can try:

remove.packages("DBI")
install.packages("DBI")
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Yujiao Li
  • 51
  • 3