odbcDataType | R Documentation |
This is used when creating a new table with dbWriteTable()
.
Databases with default methods defined are
MySQL
PostgreSQL
SQL Server
Oracle
SQLite
Spark
Hive
Impala
Redshift
Vertica
BigQuery
Teradata
Access
odbcDataType(con, obj, ...)
con |
A driver connection object, as returned by |
obj |
An R object. |
... |
Additional arguments passed to methods. |
If you are using a different database and dbWriteTable()
fails with a SQL
parsing error the default method is not appropriate, you will need to write
a new method.
Corresponding SQL type for the obj
.
The object type for your connection will be the database name retrieved by
dbGetInfo(con)$dbms.name
. Use the documentation provided with your
database to determine appropriate values for each R data type. An example
method definition of a fictional foo
database follows.
con <- dbConnect(odbc::odbc(), "FooConnection") dbGetInfo(con)$dbms.name #> [1] "foo" `odbcDataType.foo <- function(con, obj, ...) { switch_type(obj, factor = "VARCHAR(255)", datetime = "TIMESTAMP", date = "DATE", binary = "BINARY", integer = "INTEGER", double = "DOUBLE", character = "VARCHAR(255)", logical = "BIT", list = "VARCHAR(255)", stop("Unsupported type", call. = FALSE) ) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.