-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling for postgres schemas? #12
Comments
Good question! I actually don't have much experience with postgres using schemas. Here's the query that we use to select the "table" to be archived: https://github.com/cboettig/arkdb/blob/295f0bc354d932aa8d75a1164e58a910744c6cbe/R/ark.R#L130-L132 Looks like we'll want to support some mechanism for a user to specify the schema, rather than just the table name, to indicate how the table should be archived? What should the corresponding |
That would be great! The table name has to be be referred to as a "qualified" name as
I'm not sure what happens when a table is not in a schema... the last line of the docs does not fill me with hope! |
hmm... can you just manually construct the appropriate |
Oh, good call. this worked:
|
Nice, thanks. I'll add that example into the documentation. Does that sound like a sufficient strategy here? |
This doesn't work for me. Maybe an update to Below is a reprex (with a PostgreSQL server run inside docker). Before that, I do want to say that this schema specification is, or has been, a bit of a mess. Depending on the case (
ReprexRun the server: docker pull postgres:12.0
docker run \
--detach \
--env POSTGRES_PASSWORD=reprex \
--name reprex \
--publish 5432:5432 \
--rm \
postgres:12.0 The R reprex: # open connection
con <-
DBI::dbConnect(
RPostgres::Postgres(),
host = "127.0.0.1",
dbname = "postgres",
user = "postgres",
password = "reprex"
)
# generate simple dummy data
x <- data.frame(i = 1:10)
# insert that into the database
DBI::dbExecute(con, "CREATE SCHEMA foobar;")
DBI::dbWriteTable(con, DBI::Id(schema = "foobar", table = "x"), x)
# check that it is there and we can read it
DBI::dbReadTable(con, DBI::Id(schema = "foobar", table = "x"))
DBI::dbGetQuery(con, "SELECT * FROM foobar.x")
# but none of these work
arkdb::ark(con, dir = tempdir(), tables = "x")
arkdb::ark(con, dir = tempdir(), tables = "foobar.x")
arkdb::ark(con, dir = tempdir(), tables = c("foobar", "x"))
arkdb::ark(con, dir = tempdir(), tables = DBI::Id(schema = "foobar", table = "x"))
arkdb::ark(con, dir = tempdir(), tables = dbplyr::in_schema(schema = "foobar", table = "x")) As a side note, even though they give errors, the commands above still generate output files. I think they shouldn't. Clean updocker stop reprex
docker rmi postgres:12.0
|
@ilarischeinin Thanks for the reprex. Yeah, as you can see, |
A note here,
|
Would it be possible to support Postgres databases that have tables in schemas? I'm running into problems I think because table names have to be prefixed by the schema name in the sql.
Error:
The text was updated successfully, but these errors were encountered: