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

Oracle: copy_to with overwrite fails #3306

Closed
EdwardJRoss opened this issue Jan 17, 2018 · 7 comments
Closed

Oracle: copy_to with overwrite fails #3306

EdwardJRoss opened this issue Jan 17, 2018 · 7 comments
Assignees
Labels
bug an unexpected problem or unintended behavior wip work in progress

Comments

@EdwardJRoss
Copy link

EdwardJRoss commented Jan 17, 2018

I am trying to send a table to an Oracle Database via ODBC ,overwriting if it already exists.
The copy_to method in Oracle via ODBC fails when overwrite=TRUE because "DROP TABLE IF EXISTS" isn't valid syntax in Oracle.

Example (without specific credentials), tested with Oracle 11.2:

con <- DBI::dbConnect(odbc::odbc(), ...)
dplyr::copy_to(con, iris, overwrite=TRUE)
#> Error: <SQL> 'DROP TABLE IF EXISTS iris'
#> nanodbc/nanodbc.cpp:1587: HY000: [Oracle][ODBC][Ora]ORA-00933: SQL command not properly ended
dplyr::copy_to(con, iris, overwrite=TRUE)
#> Error in connection_begin(conn@ptr) : Double begin

Expected result:
The table iris is loaded to the database, being overwritten if it already exists.

Actual Result:
There is an error, and the connection can no longer be used (it seems the transaction isn't aborted on failure).

I also tried using ROracle but copy_to seems to fail when attempting to start a transaction:

con <- DBI::dbConnect(DBI::dbDriver("Oracle"), ...)
dplyr::copy_to(con, iris)
#> Error in (function (classes, fdef, mtable)  : 
#>  unable to find an inherited method for function 'dbBegin' for signature '"OraConnection"'
@krlmlr
Copy link
Member

krlmlr commented Jan 17, 2018

Thanks for reporting this. Is there an equivalent to DROP TABLE IF EXISTS in Oracle?

@krlmlr krlmlr added bug an unexpected problem or unintended behavior database labels Jan 17, 2018
@EdwardJRoss
Copy link
Author

Unfortunately only a messy one, try to drop the table and catch the "table not exists error" if it is thrown.

BEGIN
   EXECUTE IMMEDIATE 'DROP TABLE <the table>';
EXCEPTION
   WHEN OTHERS THEN
      IF SQLCODE != -942 THEN
         RAISE;
      END IF;
END;

@krlmlr
Copy link
Member

krlmlr commented Jan 18, 2018

Thanks. This could be good enough for dbplyr, if we can't do any better.

@hadley
Copy link
Member

hadley commented May 20, 2018

@edgararuiz do you want to take this one?

@edgararuiz-zz
Copy link

Yes, I'll take this one

@ghost
Copy link

ghost commented Jun 25, 2018

This issue was moved by krlmlr to tidyverse/dbplyr/issues/120.

@ghost ghost closed this as completed Jun 25, 2018
@lock
Copy link

lock bot commented Dec 22, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Dec 22, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior wip work in progress
Projects
None yet
Development

No branches or pull requests

4 participants