Created
May 29, 2019 17:38
-
-
Save jsfenfen/67a08dd9b479b6405a3ed52bfd411728 to your computer and use it in GitHub Desktop.
RPostgreSQL connect
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") | |
# connect to postgres | |
drv <- dbDriver("PostgreSQL") | |
con <- dbConnect(drv, dbname = "database_name", | |
host = "localhost", port = 5432, | |
user = "user_name") | |
# execute query | |
sql <- "SELECT count(*) FROM x" | |
df <- dbGetQuery(con, sql) | |
# disconnect | |
dbDisconnect(con) | |
dbUnloadDriver(drv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment