/
dbAppendTable.Rd
195 lines (171 loc) · 6.45 KB
/
dbAppendTable.Rd
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/11-dbAppendTable.R
\name{dbAppendTable}
\alias{dbAppendTable}
\title{Insert rows into a table}
\usage{
dbAppendTable(conn, name, value, ..., row.names = NULL)
}
\arguments{
\item{conn}{A \linkS4class{DBIConnection} object, as returned by
\code{\link[=dbConnect]{dbConnect()}}.}
\item{name}{The table name, passed on to \code{\link[=dbQuoteIdentifier]{dbQuoteIdentifier()}}. Options are:
\itemize{
\item a character string with the unquoted DBMS table name,
e.g. \code{"table_name"},
\item a call to \code{\link[=Id]{Id()}} with components to the fully qualified table name,
e.g. \code{Id(schema = "my_schema", table = "table_name")}
\item a call to \code{\link[=SQL]{SQL()}} with the quoted and fully qualified table name
given verbatim, e.g. \code{SQL('"my_schema"."table_name"')}
}}
\item{value}{A \link{data.frame} (or coercible to data.frame).}
\item{...}{Other parameters passed on to methods.}
\item{row.names}{Must be \code{NULL}.}
}
\value{
\code{dbAppendTable()} returns a
scalar
numeric.
}
\description{
The \code{dbAppendTable()} method assumes that the table has been created
beforehand, e.g. with \code{\link[=dbCreateTable]{dbCreateTable()}}.
The default implementation calls \code{\link[=sqlAppendTableTemplate]{sqlAppendTableTemplate()}} and then
\code{\link[=dbExecute]{dbExecute()}} with the \code{param} argument.
Use \code{\link[=dbAppendTableArrow]{dbAppendTableArrow()}} to append data from an Arrow stream.
\Sexpr[results=rd,stage=render]{DBI:::methods_as_rd("dbAppendTable")}
}
\details{
Backends compliant to
ANSI SQL 99 which use \verb{?} as a placeholder for prepared queries don't need
to override it. Backends with a different SQL syntax which use \verb{?}
as a placeholder for prepared queries can override \code{\link[=sqlAppendTable]{sqlAppendTable()}}.
Other backends (with different placeholders or with entirely different
ways to create tables) need to override the \code{dbAppendTable()} method.
The \code{row.names} argument is not supported by this method.
Process the values with \code{\link[=sqlRownamesToColumn]{sqlRownamesToColumn()}} before calling this method.
}
\section{Failure modes}{
If the table does not exist,
or the new data in \code{values} is not a data frame or has different column names,
an error is raised; the remote table remains unchanged.
An error is raised when calling this method for a closed
or invalid connection.
An error is also raised
if \code{name} cannot be processed with \code{\link[=dbQuoteIdentifier]{dbQuoteIdentifier()}} or
if this results in a non-scalar.
Invalid values for the \code{row.names} argument
(non-scalars,
unsupported data types,
\code{NA})
also raise an error.
Passing a \code{value} argument different to \code{NULL} to the \code{row.names} argument
(in particular \code{TRUE},
\code{NA},
and a string)
raises an error.
}
\section{Specification}{
SQL keywords can be used freely in table names, column names, and data.
Quotes, commas, spaces, and other special characters such as newlines and tabs,
can also be used in the data,
and, if the database supports non-syntactic identifiers,
also for table names
and column names.
The following data types must be supported at least,
and be read identically with \code{\link[=dbReadTable]{dbReadTable()}}:
\itemize{
\item integer
\item numeric
(the behavior for \code{Inf} and \code{NaN} is not specified)
\item logical
\item \code{NA} as NULL
\item 64-bit values (using \code{"bigint"} as field type); the result can be
\itemize{
\item converted to a numeric, which may lose precision,
\item converted a character vector, which gives the full decimal
representation
\item written to another table and read again unchanged
}
\item character (in both UTF-8
and native encodings),
supporting empty strings
(before and after non-empty strings)
\item factor (returned as character,
with a warning)
\item list of raw
(if supported by the database)
\item objects of type \link[blob:blob]{blob::blob}
(if supported by the database)
\item date
(if supported by the database;
returned as \code{Date})
also for dates prior to 1970 or 1900 or after 2038
\item time
(if supported by the database;
returned as objects that inherit from \code{difftime})
\item timestamp
(if supported by the database;
returned as \code{POSIXct}
respecting the time zone but not necessarily preserving the
input time zone),
also for timestamps prior to 1970 or 1900 or after 2038
respecting the time zone but not necessarily preserving the
input time zone)
}
Mixing column types in the same table is supported.
The \code{name} argument is processed as follows,
to support databases that allow non-syntactic names for their objects:
\itemize{
\item If an unquoted table name as string: \code{dbAppendTable()} will do the quoting,
perhaps by calling \code{dbQuoteIdentifier(conn, x = name)}
\item If the result of a call to \code{\link[=dbQuoteIdentifier]{dbQuoteIdentifier()}}: no more quoting is done
to support databases that allow non-syntactic names for their objects:
}
The \code{row.names} argument must be \code{NULL}, the default value.
Row names are ignored.
The \code{value} argument must be a data frame
with a subset of the columns of the existing table.
The order of the columns does not matter.
}
\examples{
\dontshow{if (requireNamespace("RSQLite", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
con <- dbConnect(RSQLite::SQLite(), ":memory:")
dbCreateTable(con, "iris", iris)
dbAppendTable(con, "iris", iris)
dbReadTable(con, "iris")
dbDisconnect(con)
\dontshow{\}) # examplesIf}
}
\seealso{
Other DBIConnection generics:
\code{\link{dbAppendTableArrow}()},
\code{\link{dbCreateTable}()},
\code{\link{dbCreateTableArrow}()},
\code{\link{dbDataType}()},
\code{\link{dbDisconnect}()},
\code{\link{dbExecute}()},
\code{\link{dbExistsTable}()},
\code{\link{dbGetException}()},
\code{\link{dbGetInfo}()},
\code{\link{dbGetQuery}()},
\code{\link{dbGetQueryArrow}()},
\code{\link{DBIConnection-class}},
\code{\link{dbIsReadOnly}()},
\code{\link{dbIsValid}()},
\code{\link{dbListFields}()},
\code{\link{dbListObjects}()},
\code{\link{dbListResults}()},
\code{\link{dbListTables}()},
\code{\link{dbQuoteIdentifier}()},
\code{\link{dbReadTable}()},
\code{\link{dbReadTableArrow}()},
\code{\link{dbRemoveTable}()},
\code{\link{dbSendQuery}()},
\code{\link{dbSendQueryArrow}()},
\code{\link{dbSendStatement}()},
\code{\link{dbUnquoteIdentifier}()},
\code{\link{dbWriteTable}()},
\code{\link{dbWriteTableArrow}()}
}
\concept{DBIConnection generics}