Remove a remote table (e.g., created by dbWriteTable()
)
from the database.
Methods in other packages
This documentation page describes the generics. Refer to the documentation pages linked below for the documentation for the methods that are implemented in various backend packages.
DatabaseConnector::dbRemoveTable("DatabaseConnectorConnection", "ANY")
RPostgreSQL::dbRemoveTable("PostgreSQLConnection", "character")
sparklyr::dbRemoveTable("spark_connection", "character")
Arguments
- conn
A DBIConnection object, as returned by
dbConnect()
.- name
The table name, passed on to
dbQuoteIdentifier()
. Options are:a character string with the unquoted DBMS table name, e.g.
"table_name"
,a call to
Id()
with components to the fully qualified table name, e.g.Id(schema = "my_schema", table = "table_name")
a call to
SQL()
with the quoted and fully qualified table name given verbatim, e.g.SQL('"my_schema"."table_name"')
- ...
Other parameters passed on to methods.
Failure modes
If the table does not exist, an error is raised. An attempt to remove a view with this function may result in an error.
An error is raised when calling this method for a closed
or invalid connection.
An error is also raised
if name
cannot be processed with dbQuoteIdentifier()
or
if this results in a non-scalar.
Additional arguments
The following arguments are not part of the dbRemoveTable()
generic
(to improve compatibility across backends)
but are part of the DBI specification:
temporary
(default:FALSE
)fail_if_missing
(default:TRUE
)
These arguments must be provided as named arguments.
If temporary
is TRUE
, the call to dbRemoveTable()
will consider only temporary tables.
Not all backends support this argument.
In particular, permanent tables of the same name are left untouched.
If fail_if_missing
is FALSE
, the call to dbRemoveTable()
succeeds if the table does not exist.
Specification
A table removed by dbRemoveTable()
doesn't appear in the list of tables
returned by dbListTables()
,
and dbExistsTable()
returns FALSE
.
The removal propagates immediately to other connections to the same database.
This function can also be used to remove a temporary table.
The name
argument is processed as follows,
to support databases that allow non-syntactic names for their objects:
If an unquoted table name as string:
dbRemoveTable()
will do the quoting, perhaps by callingdbQuoteIdentifier(conn, x = name)
If the result of a call to
dbQuoteIdentifier()
: no more quoting is done
See also
Other DBIConnection generics:
DBIConnection-class
,
dbAppendTable()
,
dbAppendTableArrow()
,
dbCreateTable()
,
dbCreateTableArrow()
,
dbDataType()
,
dbDisconnect()
,
dbExecute()
,
dbExistsTable()
,
dbGetException()
,
dbGetInfo()
,
dbGetQuery()
,
dbGetQueryArrow()
,
dbIsReadOnly()
,
dbIsValid()
,
dbListFields()
,
dbListObjects()
,
dbListResults()
,
dbListTables()
,
dbQuoteIdentifier()
,
dbReadTable()
,
dbReadTableArrow()
,
dbSendQuery()
,
dbSendQueryArrow()
,
dbSendStatement()
,
dbUnquoteIdentifier()
,
dbWriteTable()
,
dbWriteTableArrow()
Examples
con <- dbConnect(RSQLite::SQLite(), ":memory:")
dbExistsTable(con, "iris")
#> [1] FALSE
dbWriteTable(con, "iris", iris)
dbExistsTable(con, "iris")
#> [1] TRUE
dbRemoveTable(con, "iris")
dbExistsTable(con, "iris")
#> [1] FALSE
dbDisconnect(con)