R: Convenience functions for reading/writing DBMS tables

odbc-tables {odbc} | R Documentation

## Convenience functions for reading/writing DBMS tables

### Description

Convenience functions for reading/writing DBMS tables

### Usage

    ## S4 method for signature 'OdbcConnection,character,data.frame'
    dbWriteTable(
      conn,
      name,
      value,
      overwrite = FALSE,
      append = FALSE,
      temporary = FALSE,
      row.names = NA,
      field.types = NULL,
      batch_rows = getOption("odbc.batch_rows", NA),
      ...
    )

    ## S4 method for signature 'OdbcConnection,Id,data.frame'
    dbWriteTable(
      conn,
      name,
      value,
      overwrite = FALSE,
      append = FALSE,
      temporary = FALSE,
      row.names = NA,
      field.types = NULL,
      batch_rows = getOption("odbc.batch_rows", NA),
      ...
    )

    ## S4 method for signature 'OdbcConnection,SQL,data.frame'
    dbWriteTable(
      conn,
      name,
      value,
      overwrite = FALSE,
      append = FALSE,
      temporary = FALSE,
      row.names = NA,
      field.types = NULL,
      batch_rows = getOption("odbc.batch_rows", NA),
      ...
    )

    ## S4 method for signature 'OdbcConnection'
    dbAppendTable(conn, name, value, ..., row.names = NULL)

    ## S4 method for signature 'OdbcConnection'
    sqlData(con, value, row.names = NA, ...)

    ## S4 method for signature 'OdbcConnection'
    sqlCreateTable(
      con,
      table,
      fields,
      field.types = NULL,
      row.names = NA,
      temporary = FALSE,
      ...
    )

### Arguments

`conn` | a `OdbcConnection` object, produced by `DBI::dbConnect()`
`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.
`overwrite` | Allow overwriting the destination table. Cannot be `TRUE` if `append` is also `TRUE`.
`append` | Allow appending to the destination table. Cannot be `TRUE` if `overwrite` is also `TRUE`.
`temporary` | If `TRUE`, will generate a temporary table statement.
`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`.
`field.types` | Additional field types used to override derived types.
`batch_rows` | The number of rows to retrieve. Defaults to `NA`, which is set dynamically to the size of the input. Depending on the database, driver, dataset and free memory setting this to a lower value may improve performance.
`...` | Other arguments used by individual methods.
`con` | A database connection.
`table` | Name of the table. Escaped with `dbQuoteIdentifier()`.
`fields` | Either a character vector or a data frame. A named character vector: Names are column names, values are types. Names are escaped with `dbQuoteIdentifier()`. Field types are unescaped. A data frame: field types are generated using `dbDataType()`.

### Examples

    ## Not run:
    library(DBI)
    con <- dbConnect(odbc::odbc())
    dbListTables(con)
    dbWriteTable(con, "mtcars", mtcars, temporary = TRUE)
    dbReadTable(con, "mtcars")

    dbListTables(con)
    dbExistsTable(con, "mtcars")

    # A zero row data frame just creates a table definition.
    dbWriteTable(con, "mtcars2", mtcars[0, ], temporary = TRUE)
    dbReadTable(con, "mtcars2")

    dbDisconnect(con)

    ## End(Not run)

[Package odbc version 1.3.2 Index]