I'm trying to use the large object (https://www.postgresql.org/docs/10/largeobjects.html) feature of PostgreSQL in R, and I have some trouble writing and reading using {DBI}
/{RPostgres}
.
Here is what I have tried so far:
# Getting the db
docker run --rm --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5433:5432 postgres
library(DBI)
con <- dbConnect(
RPostgres::Postgres(),
dbname = "postgres",
host = "localhost",
port = 5433,
user = "postgres",
password = "mysecretpassword"
)
Creation works :
> dbGetQuery(con, "SELECT lo_create(1234);")
lo_create
1 1234
But then I have a hard time figuring out how to write an R object to this large object.
For example, how would I write mtcars
as a large object in Postgres using {DBI}
and {RPostgres}
?
And then, how do I read it back again in R?