Skip to content

Instantly share code, notes, and snippets.

@jsfenfen
Created May 29, 2019 17:38
Show Gist options
  • Save jsfenfen/67a08dd9b479b6405a3ed52bfd411728 to your computer and use it in GitHub Desktop.
Save jsfenfen/67a08dd9b479b6405a3ed52bfd411728 to your computer and use it in GitHub Desktop.
RPostgreSQL connect
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