-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy path13-dbWriteTable.R
More file actions
56 lines (56 loc) · 2.1 KB
/
Copy path13-dbWriteTable.R
File metadata and controls
56 lines (56 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#' Copy data frames to database tables
#'
#' Writes, overwrites or appends a data frame to a database table, optionally
#' converting row names to a column and specifying SQL data types for fields.
#'
#' @details
#' This function expects a data frame.
#' Use [dbWriteTableArrow()] to write an Arrow object.
#'
#' This function is useful if you want to create and load a table at the same time.
#' Use [dbAppendTable()] or [dbAppendTableArrow()] for appending data to an existing
#' table, [dbCreateTable()] or [dbCreateTableArrow()] for creating a table,
#' and [dbExistsTable()] and [dbRemoveTable()] for overwriting tables.
#'
#' DBI only standardizes writing data frames with `dbWriteTable()`.
#' Some backends might implement methods that can consume CSV files
#' or other data formats.
#' For details, see the documentation for the individual methods.
#'
#' @template methods
#' @templateVar method_name dbWriteTable
#'
#' @inherit DBItest::spec_sql_write_table return
#' @inheritSection DBItest::spec_sql_write_table Failure modes
#' @inheritSection DBItest::spec_sql_write_table Additional arguments
#' @inheritSection DBItest::spec_sql_write_table Specification
#'
#' @inheritParams dbGetQuery
#' @inheritParams dbReadTable
#' @param value A [data.frame] (or coercible to data.frame).
#' @family DBIConnection generics
#' @export
#' @examplesIf requireNamespace("RSQLite", quietly = TRUE)
#' con <- dbConnect(RSQLite::SQLite(), ":memory:")
#'
#' dbWriteTable(con, "mtcars", mtcars[1:5, ])
#' dbReadTable(con, "mtcars")
#'
#' dbWriteTable(con, "mtcars", mtcars[6:10, ], append = TRUE)
#' dbReadTable(con, "mtcars")
#'
#' dbWriteTable(con, "mtcars", mtcars[1:10, ], overwrite = TRUE)
#' dbReadTable(con, "mtcars")
#'
#' # No row names
#' dbWriteTable(con, "mtcars", mtcars[1:10, ], overwrite = TRUE, row.names = FALSE)
#' dbReadTable(con, "mtcars")
setGeneric("dbWriteTable", def = function(conn, name, value, ...) {
otel_local_active_span(
"dbWriteTable",
conn,
label = .dbi_get_collection_name(name, conn),
attributes = list(db.collection.name = .dbi_get_collection_name(name, conn))
)
standardGeneric("dbWriteTable")
})