sqlReplaceInTable: Compose query to update rows in a table

Description Usage Arguments Details See Also Examples

Description

'sqlReplaceInTable()' generates a single SQL string that inserts a data frame into an existing table. 'sqlReplaceTableTemplate()' generates a template suitable for use with [dbBind()]. The default methods are MariaDB, MySQL compliant. These methods are mostly useful for backend implementers.

Usage

1
2
3
4
sqlReplaceInTable(con, table, values, row.names = NA, ...)

sqlReplaceInTableTemplate(con, table, values, row.names = NA,
  prefix = "?", ..., pattern = "")

Arguments

con

A database connection.

table

Name of the table. Escaped with dbQuoteIdentifier().

values

A data frame. Factors will be converted to character vectors. Character vectors will be escaped with [dbQuoteString()].

row.names

Either TRUE, FALSE, NA or a string.

If TRUE, always translate row names to a column called "row_names". If FALSE, never translate row names. If NA, translate rownames only if they're a character vector.

A string is equivalent to TRUE, but allows you to override the default name.

For backward compatibility, NULL is equivalent to FALSE.

...

Other arguments used by individual methods.

prefix

Parameter prefix to use for placeholders.

pattern

Parameter pattern to use for placeholders: - '""': no pattern - '"1"': position - anything else: field name

Details

The 'row.names' argument must be passed explicitly in order to avoid a compatibility warning. The default will be changed in a later release.

See Also

Other SQL generation: sqlAddIndex, sqlAlterTableWithPrimaryKey, sqlDeleteAllRecords, sqlOnClause, sqlSetClause, sqlUpdateTable

Examples

1
2
3
4
5
6
7
8
sqlReplaceInTable(ANSI(), "iris", head(iris))

sqlReplaceInTable(ANSI(), "mtcars", head(mtcars))
sqlReplaceTable(ANSI(), "mtcars", head(mtcars), row.names = FALSE)
sqlAppendTableTemplate(ANSI(), "iris", iris)

sqlAppendTableTemplate(ANSI(), "mtcars", mtcars)
sqlAppendTableTemplate(ANSI(), "mtcars", mtcars, row.names = FALSE)

schardtbc/DBIExt documentation built on June 7, 2019, 2:39 p.m.