On Oracle I have a table with SDO_GEOMETRY data type:
CREATE TABLE T_GEO_TABLE
(
"LONGITUDE" DOUBLE,
"LATITUDE" DOUBLE,
"GEO" "SDO_GEOMETRY"
);
In R i have a data frame with longitude and latitude. I want to write this table to Oracle with DBI (RJDBC) and populate the "GEO" field later with an UPDATE statement in SQL.
The function dbWriteTable requires the R table to have exactly the same columns as the database table. If I make an empty column "GEO" in R and try to write this table to Oracle:
r_table <- r_table %>% mutate(GEO = NA)
dbWriteTable(conn = con_oracle, name = "T_GEO_TABLE", value = r_table, overwrite = FALSE, append = TRUE)
, I get an error: ORA-00932: inconsistent datatypes: expected MDSYS.SDO_GEOMETRY got CHAR. The same thing happens of course with other NA types (NA_character_, NA_integer, ...).
The obvious solution is to insert first into a temporary table on Oracle with only longitude and latitude columns and then do the rest in SQL with dbSendUpdate.
Is there an elegant way to achieve this without the temp table? My question is not specific to SDO_GEOMETRY type. Can you somehow force a DBI function to insert into only a subset of columns.
create table r2temp (a int, b int, c int), I can then doDBI::dbWriteTable(con, "r2temp", data.frame(a=1L), create=F, overwrite=F, append=T)and it works. DoesRJDBCspecifically impose this restriction? It isn'tDBI, and this seems like an onerous (and unnecessary) constraint that should be handled at the table level (e.g.,b INT NOT NULL).DBI::dbWriteTable(con_oracle, "tt_temp", data.frame(a=1L), create=F, overwrite=F, append=T), I getError in .local(conn, statement, ...) : execute JDBC update query failed in dbSendUpdate (ORA-00955: name is already used by an existing object). WithDBI::dbWriteTable(con_oracle, "TT_TEMP", data.frame(a=1L), create=F, overwrite=F, append=T)I getError in .local(conn, statement, ...) : execute JDBC update query failed in dbSendUpdate (ORA-00947: not enough values). Thanks anyway.name is already usedsuggests that the RJDBC driver is ignoring or misinterpreting thecreate=,overwrite=, and/orappend=arguments. Sorry, since I don't use RJDBC, I can only comment on how DBI and ODBC are supposed to work given its specification and such. It works in other DBMSes, certainly suggesting either a key difference in Oracle (certainly possible), in JDBC (on which RJDBC relies), or lacking both of those possibly a mis-implementation in RJDBC (I'm assuming it's one of the first two, but who knows).