library(DBI)
library(RPostgres)
library(tidyverse)── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.1 ✔ stringr 1.5.2
✔ ggplot2 4.0.1 ✔ tibble 3.3.0
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.1.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
con <- dbConnect(
RPostgres::Postgres(),
dbname = "data_607",
host = "localhost",
port = 5432,
user = "postgres"
)
ratings_df <- dbGetQuery(con, "
SELECT u.user_id, u.name, m.movie_id, m.title, r.rating
FROM ratings r
JOIN users u ON r.user_id = u.user_id
JOIN movies m ON r.movie_id = m.movie_id
ORDER BY u.name, m.movie_id;
")
users_df <- dbGetQuery(con, "SELECT user_id, name FROM users ORDER BY user_id;")
movies_df <- dbGetQuery(con, "SELECT movie_id, title FROM movies ORDER BY movie_id;")
dbDisconnect(con)