Question: How can RPostgreSQL be used to query a database table based on a variable containing a vector of primary keys?
Example: In this I have the following code which works for one instance, but does not work when I try to vectorize it.
library(RPostgreSQL)
Pkey <- 100231
connect <- dbConnect(PostgreSQL(),
dbname="test",
host="localhost",
port=5432,
user="user",
password="...")
query <- paste0("SELECT * FROM sales_tbl WHERE id='", Pkey, "'")
result <- dbGetQuery(connect, query)
Example Vectorization Pkey (Does not work):
library(RPostgreSQL)
Pkey <- list$Pkey # This is the change.
connect <- dbConnect(PostgreSQL(),
dbname="test",
host="localhost",
port=5432,
user="user",
password="...")
query <- paste0("SELECT * FROM sales_tbl WHERE id='", Pkey, "'")
result <- dbGetQuery(connect, query)