Created
June 28, 2017 09:01
-
-
Save allenaven/cb7221e8b537f00709cf85a098141b3c to your computer and use it in GitHub Desktop.
Example R dplyr connection to a Postgres database, since I have to look it up every time I code it...
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
## Connect to a local Postgres database running in a Docker container | |
## although the Docker part isn't of any importance here. | |
## Working with dplyr 0.7, DBI 0.7, dbplyr 1.1.0 | |
library(DBI) | |
library(dplyr) | |
library(dbplyr) | |
con <- DBI::dbConnect(RPostgreSQL::PostgreSQL(), host = 'localhost', port = 8990, | |
dbname = <name of db>, user = <user>, password = <pass>) | |
DBI::dbListTables(con) | |
deployments <- tbl(con, <name of table>) | |
dbExistsTable(con, <name of table>) | |
t <- dbGetQuery(con, <name of table>) | |
dbDisconnect(con) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment