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

NISHIYAMA Tomoaki tomo@k|n @end|ng |rom @t@||@k@n@z@w@-u@@c@jp
Fri Oct 17 02:12:50 CEST 2014


Hi,

> > 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 ...?

On the manual of dbConnect(drv, ...) in
http://cran.r-project.org/web/packages/DBI/DBI.pdf
the argument ... is explained as
	authorization arguments needed by the DBMS instance; 
	these typically include user, password, dbname, host, port, etc. 
	For details see the appropriate DBIDriver.

There is no implication that the first unnamed argument be dbname.
Because no order is specified in the manual, the parameter name should
be explicitly written always. 
-- 
Tomoaki NISHIYAMA

Advanced Science Research Center,
Kanazawa University,
13-1 Takara-machi, 
Kanazawa, 920-0934, Japan


On 2014/10/17, at 3:35, Paul Gilbert wrote:

> 
> 
> 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