rows-db {dm} | R Documentation |
These methods provide a framework for manipulating individual rows in existing tables. All operations expect that both existing and new data are presented in two compatible tbl objects.
If y
lives on a different data source than x
, it can be copied automatically
by setting copy = TRUE
, just like for dplyr::left_join()
.
On mutable backends like databases, these operations manipulate the
underlying storage.
In contrast to all other operations,
these operations may lead to irreversible changes to the underlying database.
Therefore, in-place updates must be requested explicitly with in_place = TRUE
.
By default, an informative message is given.
Unlike compute()
or copy_to()
, no new tables are created.
The sql_rows_*()
functions return the SQL used for the corresponding
rows_*()
function with in_place = FALSE
.
y
needs to be located on the same data source as x
.
sql_returning_cols()
and sql_output_cols()
construct the SQL
required to support the returning
argument.
Two methods are required, because the syntax for SQL Server
(and some other databases) is vastly different from Postgres and other
more standardized DBs.
## S3 method for class 'tbl_dbi'
rows_insert(
x,
y,
by = NULL,
...,
in_place = NULL,
copy = FALSE,
check = NULL,
returning = NULL
)
## S3 method for class 'tbl_dbi'
rows_update(
x,
y,
by = NULL,
...,
in_place = NULL,
copy = FALSE,
check = NULL,
returning = NULL
)
## S3 method for class 'tbl_dbi'
rows_patch(
x,
y,
by = NULL,
...,
in_place = NULL,
copy = FALSE,
check = NULL,
returning = NULL
)
## S3 method for class 'tbl_dbi'
rows_upsert(
x,
y,
by = NULL,
...,
in_place = NULL,
copy = FALSE,
check = NULL,
returning = NULL
)
## S3 method for class 'tbl_dbi'
rows_delete(
x,
y,
by = NULL,
...,
in_place = NULL,
copy = FALSE,
check = NULL,
returning = NULL
)
sql_rows_insert(x, y, ..., returning_cols = NULL)
sql_rows_update(x, y, by, ..., returning_cols = NULL)
sql_rows_patch(x, y, by, ..., returning_cols = NULL)
sql_rows_delete(x, y, by, ..., returning_cols = NULL)
sql_returning_cols(x, returning_cols, ...)
sql_output_cols(x, returning_cols, output_delete = FALSE, ...)
x |
A pair of data frames or data frame extensions (e.g. a tibble).
|
y |
A pair of data frames or data frame extensions (e.g. a tibble).
|
by |
An unnamed character vector giving the key columns. The key
values must uniquely identify each row (i.e. each combination of key
values occurs at most once), and the key columns must exist in both By default, we use the first column in |
... |
Other parameters passed onto methods. |
in_place |
Should When |
copy |
If |
check |
Set to Currently these checks are no-ops and need yet to be implemented. |
returning |
Due to upstream limitations, a warning is given if this argument
is passed unquoted.
To avoid the warning, quote the argument manually:
use e.g. |
returning_cols |
A character vector of unquote column names
to return, created from the |
output_delete |
For |
A tbl object of the same structure as x
.
If in_place = TRUE
, the underlying data is updated as a side effect,
and x
is returned, invisibly. If return columns are specified with
returning
then the resulting tibble is stored in the attribute
returned_rows
. This can be accessed with get_returned_rows()
.
data <- dbplyr::memdb_frame(a = 1:3, b = letters[c(1:2, NA)], c = 0.5 + 0:2)
data
try(rows_insert(data, tibble::tibble(a = 4, b = "z")))
rows_insert(data, tibble::tibble(a = 4, b = "z"), copy = TRUE)
rows_update(data, tibble::tibble(a = 2:3, b = "w"), copy = TRUE, in_place = FALSE)
rows_patch(data, dbplyr::memdb_frame(a = 1:4, c = 0), in_place = FALSE)
rows_insert(data, dbplyr::memdb_frame(a = 4, b = "z"), in_place = TRUE)
data
rows_update(data, dbplyr::memdb_frame(a = 2:3, b = "w"), in_place = TRUE)
data
rows_patch(data, dbplyr::memdb_frame(a = 1:4, c = 0), in_place = TRUE)
data