Skip to content
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

Creation of empty tables on PG DB works but throws error #847

Open
TSchiefer opened this issue Feb 23, 2022 · 5 comments · May be fixed by #2022
Open

Creation of empty tables on PG DB works but throws error #847

TSchiefer opened this issue Feb 23, 2022 · 5 comments · May be fixed by #2022
Milestone

Comments

@TSchiefer
Copy link
Member

IIRC, roughly the workflow is the following when calling copy_dm_to():

  1. create empty tables on DB
  2. set keys
  3. insert data

I would like to copy only empty tables, to prepare a DB for later insertion of data.
The result after the call is the desired one: the tables are there and key relations are all set, but the function runs into a dbAppendTable()-call which fails.

I think even if there is another preferrable method for doing this, we could make this work.

@krlmlr
Copy link
Collaborator

krlmlr commented Feb 24, 2022

So, dbAppendTable() fails on Postgres for empty tables? We need to fix there, or work around here.

Does it work with SQL Server?

@TSchiefer
Copy link
Member Author

It works with SQL Server

krlmlr added a commit that referenced this issue Feb 27, 2022
@krlmlr
Copy link
Collaborator

krlmlr commented Feb 27, 2022

Thanks! Worked around here, can you please open an issue in DBItest so that we can add a test there and fix all affected backends?

@TSchiefer
Copy link
Member Author

I need to apologize, the issue description was a bit misleading:
When creating a reprex I realized that the culprit was the argument copy = FALSE:

library(tibble)
con_pg <- DBI::dbConnect(RPostgres::Postgres())
t1 <- tibble(a = integer())
DBI::dbWriteTable(con_pg, "t1", t1, temporary = FALSE)
DBI::dbAppendTable(con_pg, "t1", t1)
#> [1] 0
# This is the error that we're seeing in `copy_dm_to()`:
DBI::dbAppendTable(con_pg, "t1", t1, copy = FALSE)
#> Error: Failed to prepare query: ERROR:  syntax error at or near ")"
#> LINE 4:   ()
#>            ^
DBI::dbAppendTable(con_pg, "t1", t1, copy = TRUE)
#> [1] 0
DBI::dbExecute(con_pg, "DROP TABLE t1")
#> [1] 0

Created on 2022-02-28 by the reprex package (v2.0.1)

@TSchiefer
Copy link
Member Author

Your workaround does of course solve it nevertheless

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment