Learn R Programming

PivotalR (version 0.1.18.5)

delete: Safely delete a db.obj object or a table/view in the database

Description

This function deletes a db.data.frame object together with the table/view that it points to. It deletes a db.Rquery object. It can also directly delete a table or view in the database. When applied onto some composite data objects, it deletes the data table wrapped by them.

Usage

# S4 method for db.data.frame
delete(x, cascade = FALSE)

# S4 method for db.Rquery delete(x)

# S4 method for character delete(x, conn.id = 1, is.temp = FALSE, cascade = FALSE)

# S4 method for arima.css.madlib delete(x)

# S4 method for summary.madlib delete(x)

# S4 method for lm.madlib delete(x)

# S4 method for lm.madlib.grps delete(x)

# S4 method for logregr.madlib delete(x)

# S4 method for logregr.madlib.grps delete(x)

# S4 method for bagging.model delete(x)

# S4 method for elnet.madlib delete(x)

# S4 method for dt.madlib delete(x)

# S4 method for dt.madlib.grps delete(x)

Arguments

x

The signature of the method.

A db.data.frame object, which points to a table or view in the database;

Or a db.Rquery object, which represents some operations on an existing db.data.frame object;

Or a string, the table/view name to delete in the database;

Or an object which is the result of madlib.arima. In the this case, the result model tables wrapped by model, residuals and statistics will be deleted.

Or an object which is the result of madlib.summary (a summary.madlib object). In this case the result table created in the database and wrapped by the attribute "summary" will be deleted.

Or an object which is the result of madlib.lm (a lm.madlib or lm.madlib.grps object). In this case, the result model table wrapped by model will be deleted.

Or an object which is the result of madlib.glm with family = "binomial" (a logregr.madlib or logregr.madlib.grps object). In this case, the result model table wrapped by model will be deleted.

Or an object which is the result of generic.bagging. In this case, all result model tables will be deleted.

Or an object which is the result of madlib.elnet. In this casem all result model tables will be deleted.

Or an object which is the result of madlib.rpart. All result tables will be deleted.

conn.id

An integer, default is 1. The connection ID to the database.

is.temp

A logical, default is FALSE. Whether the table/view is temporary.

cascade

A logical, default is FALSE. Whether to delete objects together with all the objects depending on it.

Value

When x is db.data.frame or table/view name, this function returns a logical value. which is TRUE if the deletion is successful.

No value is returned if x is db.Rquery

Details

When a db.data.frame object is deleted, the table/view that is associated with it is also deleted.

See Also

db.data.frame creates an object pointing to a table/view in the database.

db.objects lists all tables and views in a database together with their schema.

db.existsObject tests whether a table/view exists in the database.

as.db.data.frame creates a db.data.frame from a data.frame, a data file or a db.Rquery.

madlib.lm, madlib.glm, madlib.summary, madlib.arima are MADlib wrapper functions whose results can be safely deleted by this function.

Examples

Run this code
# NOT RUN {
<!-- %% @test .port Database port number -->
<!-- %% @test .dbname Database name -->
## set up the database connection
## Assume that .port is port number and .dbname is the database name
cid <- db.connect(port = .port, dbname = .dbname, verbose = FALSE)

delete("abalone", cid, is.temp = TRUE)

delete("abalone", cid, is.temp = FALSE)

delete("abalone", conn.id = cid)
x <- as.db.data.frame(abalone, "abalone", conn.id = cid)

lk(x, 10)

y <- as.db.data.frame(abalone, "abalone", conn.id = cid, is.temp = TRUE)

lk(y, 10)

db.existsObject("abalone", cid, is.temp = TRUE)

db.existsObject("abalone", cid, is.temp = FALSE)

delete("abalone", cid)

p <- db.objects()
p[p == "abalone"]

## Example: delete multiple tables
## all table in public schema start with "ornste"
to.delete <- db.objects("public.ornste", conn.id = cid)
for (table.name in to.delete) delete(table.name, conn.id = cid)

db.disconnect(cid, verbose = FALSE)
# }

Run the code above in your browser using DataLab