get_postgres_connection: Connect to a PostgreSQL database

View source: R/database.R

get_postgres_connectionR Documentation

Connect to a PostgreSQL database

Description

This function initiates a PostgreSQL connection using stored database credentials through the keyring package.

Usage

get_postgres_connection(keyring_name, service_name)

Arguments

keyring_name

A character string providing the name of the keyring.

service_name

A character string providing the name of the key.

Value

A PostgreSQL database connection object.

Connect

library(DBI)
library(odbc)

# connect to database, using keyring stored credentials
con <- get_postgres_connection(keyring_name = "keyring_name",
                               service_name = "database_name")

Query

More information on working with databases using R can be found in RStudio's Databases using R webpages.

# list tables
dbListTables(con)

# get table
database_table <- tbl(con, "table_name") %>% collect()

# get query
database_query <- dbGetQuery(con, "sql_statement")
database_query <- tbl(con, sql("sql_statement")) %>% collect()

Disconnect

dbDisconnect(con)

See Also

Other database functions: get_mysql_connection(), get_sqlserver_connection()


gcfrench/store documentation built on May 17, 2024, 5:52 p.m.