Determine the SQL data type of an object

This is a generic function. The default method determines the SQL type of an R object according to the SQL 92 specification, which may serve as a starting point for driver implementations. The default method also provides a method for data.frame which will return a character vector giving the type for each column in the dataframe.

dbDataType(dbObj, obj, ...)
A object inheriting from DBIDriver or DBIConnection
An R object whose SQL type we want to determine.
Other arguments passed on to methods.

The data types supported by databases are different than the data types in R, but the mapping between the primitve types is straightforward: Any of the many fixed and varying length character types are mapped to character vectors. Fixed-precision (non-IEEE) numbers are mapped into either numeric or integer vectors.

Notice that many DBMS do not follow IEEE arithmetic, so there are potential problems with under/overflows and loss of precision.


A character string specifying the SQL data type for obj.

See Also

Other DBIDriver generics: DBIDriver-class, dbConnect, dbDriver, dbGetInfo, dbIsValid, dbListConnections

Other DBIConnection generics: DBIConnection-class, dbDisconnect, dbExecute, dbExistsTable, dbGetException, dbGetInfo, dbGetQuery, dbIsValid, dbListFields, dbListResults, dbListTables, dbReadTable, dbRemoveTable, dbSendQuery, dbSendStatement

  • dbDataType
library(DBI) dbDataType(ANSI(), 1:5) dbDataType(ANSI(), 1) dbDataType(ANSI(), TRUE) dbDataType(ANSI(), Sys.Date()) dbDataType(ANSI(), Sys.time()) dbDataType(ANSI(), Sys.time() - as.POSIXct(Sys.Date())) dbDataType(ANSI(), c("x", "abc")) dbDataType(ANSI(), list(raw(10), raw(20))) dbDataType(ANSI(), I(3)) dbDataType(ANSI(), iris) con <- dbConnect(RSQLite::SQLite(), ":memory:") dbDataType(con, 1:5) dbDataType(con, 1) dbDataType(con, TRUE) dbDataType(con, Sys.Date()) dbDataType(con, Sys.time()) dbDataType(con, Sys.time() - as.POSIXct(Sys.Date())) dbDataType(con, c("x", "abc")) dbDataType(con, list(raw(10), raw(20))) dbDataType(con, I(3)) dbDataType(con, iris) dbDisconnect(con)
Documentation reproduced from package DBI, version 0.5-1, License: LGPL (>= 2)

Community examples

Looks like there are no examples yet.