Created
July 6, 2012 13:11
-
-
Save hernamesbarbara/3060079 to your computer and use it in GitHub Desktop.
how to connect to a postgreSQL database from R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(RPostgreSQL) #import the library | |
driver <- dbDriver('PostgreSQL') #define the database driver | |
db <- dbConnect(driver, host='foobar_host', #set the host to the postgreSQL IP or alias | |
user='foo_bar', #input username | |
password='my_secret_code', #input your password | |
dbname='my_gp_db') #input the name of the databse | |
myquery <- "SELECT | |
col_one | |
,col_two | |
,col_three | |
FROM table_one a | |
INNER JOIN table_two b | |
ON a.id = b.a_id | |
WHERE | |
a.created_date > 2012 | |
LIMIT 100;" | |
my.data <- dbGetQuery(db, myquery) #assign results to a vector |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment