After spending too much time trying to get to the bottom of this issue, I want to record the answer for posterity. Actually having the schema is not necessary in dbReadTable
, but putting the table name in uppercase is. That is, the call should be
dbReadQuery(con, "TABLE_NAME")
Why?
To find out how dbReadTable
is different from a dbGetQuery
with a select * from table
call, I dug for the source:
> showMethods("dbReadTable")
Function: dbReadTable (package DBI)
conn="OraConnection", name="character"
So it's an S4 method. We use getMethod
with the above signature:
> getMethod("dbReadTable", signature = c(conn = "OraConnection", name = "character"))
Method Definition:
function (conn, name, ...)
{
.local <- function (conn, name, schema = NULL, row.names = NULL,
...)
.oci.ReadTable(conn, name, schema = schema, row.names = row.names)
.local(conn, name, ...)
}
<environment: namespace:ROracle>
.oci.ReadTable
can be found here, in the source of ROracle. All it does is check argument validity, call dbGetQuery
, and set row names. The relevant part (calling dbGetQuery
) is here:
# form name
if (is.null(schema))
tab <- sprintf('"%s"', name)
else
tab <- sprintf('"%s"."%s"', schema, name)
# read table
qry <- paste('select *',
'from', tab)
res <- .oci.GetQuery(con, qry)
Note that if a schema isn't specified, the table name is used without the "schema." prefix. However, sprintf
produces a quoted string for the table name, and quoted table names are case sensitive! (dbGetQuery
just passes an unquoted table name which can be lowercase.)
So that's why dbGetQuery(con, "select count(*) from table_name")
works, as does dbReadQuery(con, "TABLE_NAME")
but dbReadQuery(con, "table_name")
doesn't.