[R-sig-DB] R and Postgres

Steve Henshaw @teve@hen@h@w @end|ng |rom gm@||@com
Tue Jul 1 22:29:17 CEST 2008


Hi

I run postgre 8.3 on linux and can access it, ive put a generic example 
of how I got it to work below, ive only used it for a database on a 
local machine.

Hope it gives you a start :)

#########

library(Rdbi)
library(RdbiPgSQL)

#establish connection
conn <- dbConnect(PgSQL(),host='host',dbname='mydatabasename',user='me')

#send query
query <- dbSendQuery(conn,"select * from my table")

#get results
results <- dbGetResult(query)

#close connection
dbDisconnect(conn)

################

Sebastian P. Luque wrote:
> On Tue, 1 Jul 2008 12:34:34 -0700,
> "Bryce Baril" <bryce using marketoutsider.com> wrote:
>
>   
>> Hello all, I'm fairly new to R, and would like to connect to Postgres.
>>     
>
>   
>> I spent some time trying to figure out how to best do this today, and
>> mostly found dead-ends and old information.
>>     
>
>   
>> Could someone please either point me to an active project, perhaps
>> with a good example on how to do this?
>>     
>
>   
>> I'm hoping to use a DBI (or DBI-like) interface, but if all else fails
>> I'm sure I can figure out ODBC.
>>     
>
> The RODBC package comes with good documentation showing this through
> ODBC.  Starting with its README helps a lot, and then ?odbcConnect and
> the other ?odbc* functions will give you the rest.  I don't know about a
> non-ODBC interface between R and PostgreSQL.
>
>
>




More information about the R-sig-DB mailing list