[R-sig-DB] DBI preferred syntax - RPostgreSQL problem

Paul Gilbert pg||bert902 @end|ng |rom gm@||@com
Thu Oct 16 20:35:21 CEST 2014



On 10/15/2014 11:46 AM, Hadley Wickham wrote:
> On Tue, Oct 14, 2014 at 5:22 PM, Paul Gilbert <pgilbert902 using gmail.com> wrote:
>> I reported earlier in this thread that this works:
>>
>> Type 'q()' to quit R.
>>> require("RPostgreSQL")
>> Loading required package: RPostgreSQL
>> Loading required package: DBI
>>> require("DBI")
>>> z <-dbConnect(RPostgreSQL::PostgreSQL(), dbname="test")   #works
>>
>> but there are some circumstance I have not isolated where if fails with the
>> same problem as this (which fails reliably):
>>
>> Type 'q()' to quit R.
>>> requireNamespace("RPostgreSQL")
>> Loading required namespace: RPostgreSQL
>>> require("DBI")
>> Loading required package: DBI
>>> z <- dbConnect(RPostgreSQL::PostgreSQL(), "test")
>> Error in postgresqlNewConnection(drv, ...) :
>>    RS-DBI driver: (could not connect test using local on dbname "test"
>> )
>>
>> For some reason, done this way it does not find my setting of environment
>> variable PGHOST, which is not localhost, and picks up test as my user name,
>> which is not correct.
>
> I suspect this is because RPostgreSQL needs some tweaks to work when
> it's not attached - it's possible it's using .onAttach instead of
> .onLoad for initialisation.

No, it is using .onLoad and loading vs attaching does not seem to be the 
issue. I've isolated a bit better, it seems to need dbname indicated, 
which is not the case for RSQLite or RMySQL:

dbConnect(RPostgreSQL::PostgreSQL(), dbname="test")   #works
dbConnect(RPostgreSQL::PostgreSQL(), "test")   #fails

 > dbConnect(RPostgreSQL::PostgreSQL(), dbname="test")   #works
<PostgreSQLConnection:(9341,5)>
 > dbConnect(RPostgreSQL::PostgreSQL(), "test")   #fails
Error in postgresqlNewConnection(drv, ...) :
   RS-DBI driver: (could not connect test using local on dbname "test"
)

I guess this must be something to do with the order of matching ...?

Paul

 >
>
> Hadley
>




More information about the R-sig-DB mailing list