R tricks >

Fetch data from a PostgreSQL database

library(DBI)

con <- dbConnect(RPostgres::Postgres(), dbname = "my_db", host = "my_host", port = 5432, user = "my_user", password = "my_password")
res <- dbSendQuery(con, "select * from records")
df <- dbFetch(con)
dbClearResult(res)
dbDisconnect(con)