dbWriteTable()
executes several SQL statements that
create/overwrite a table and fill it with values.
RPostgres does not use parameterised queries to insert rows because
benchmarks revealed that this was considerably slower than using a single
SQL string.
dbAppendTable()
is overridden because RPostgres
uses placeholders of the form $1
, $2
etc. instead of ?
.
# S4 method for PqConnection,character,data.frame dbWriteTable( conn, name, value, ..., row.names = FALSE, overwrite = FALSE, append = FALSE, field.types = NULL, temporary = FALSE, copy = TRUE ) # S4 method for PqConnection sqlData(con, value, row.names = FALSE, ...) # S4 method for PqConnection dbAppendTable(conn, name, value, ..., row.names = NULL) # S4 method for PqConnection,character dbReadTable(conn, name, ..., check.names = TRUE, row.names = FALSE) # S4 method for PqConnection dbListTables(conn, ...) # S4 method for PqConnection,character dbExistsTable(conn, name, ...) # S4 method for PqConnection,Id dbExistsTable(conn, name, ...) # S4 method for PqConnection,character dbRemoveTable(conn, name, ..., temporary = FALSE, fail_if_missing = TRUE) # S4 method for PqConnection,character dbListFields(conn, name, ...) # S4 method for PqConnection,Id dbListFields(conn, name, ...) # S4 method for PqConnection dbListObjects(conn, prefix = NULL, ...)
conn | a PqConnection object, produced by
|
---|---|
name | a character string specifying a table name. Names will be automatically quoted so you can use any sequence of characters, not just any valid bare table name. |
value | A data.frame to write to the database. |
... | Ignored. |
row.names | Either If A string is equivalent to For backward compatibility, |
overwrite | a logical specifying whether to overwrite an existing table
or not. Its default is |
append | a logical specifying whether to append to an existing table
in the DBMS. Its default is |
field.types | character vector of named SQL field types where
the names are the names of new table's columns. If missing, types inferred
with |
temporary | If |
copy | If |
con | A database connection. |
check.names | If |
fail_if_missing | If |
prefix | A fully qualified path in the database's namespace, or |
#>#> #> #>library(DBI) if (run) con <- dbConnect(RPostgres::Postgres()) if (run) dbListTables(con) if (run) dbWriteTable(con, "mtcars", mtcars, temporary = TRUE) if (run) dbReadTable(con, "mtcars") if (run) dbListTables(con) if (run) dbExistsTable(con, "mtcars") # A zero row data frame just creates a table definition. if (run) dbWriteTable(con, "mtcars2", mtcars[0, ], temporary = TRUE) if (run) dbReadTable(con, "mtcars2") if (run) dbDisconnect(con)