[R-sig-DB] dbWriteTable in RPostgreSQL can't handle date and timestamp data types.

Tomoaki NISHIYAMA tomo@k|n @end|ng |rom kenroku@k@n@z@w@-u@@c@jp
Sun Mar 6 17:07:24 CET 2011


Hi,

> I have  data fram with columns of type date and timestamps, but
> dbWriteTable create text data type columns for them both, is it a bug?


It is just not implemented.
The relevant code is in PostgreSQLSupport.R:

## find a suitable SQL data type for the R/S object obj
## TODO: Lots and lots!! (this is a very rough first draft)
## need to register converters, abstract out PostgreSQL and generalize
## to Oracle, Informix, etc.  Perhaps this should be table-driven.
## NOTE: PostgreSQL data types differ from the SQL92 (e.g., varchar  
truncate
## trailing spaces).
postgresqlDataType <- function(obj, ...) {
     rs.class <- data.class(obj)    ## this differs in R 1.4 from  
older vers
     rs.mode <- storage.mode(obj)
     if(rs.class=="numeric" || rs.class == "integer"){
         sql.type <- if(rs.mode=="integer") "bigint" else  "float8"
     }
     else {
         sql.type <- switch(rs.class,
                            character = "text",
                            logical = "bool",
                            factor = "text",
                            ordered = "text",
                            "text")
     }
     sql.type
}


This is all the default conversion.
For any other type, you need to do write respective codes.
-- 
Tomoaki NISHIYAMA

Advanced Science Research Center,
Kanazawa University,
13-1 Takara-machi,
Kanazawa, 920-0934, Japan




More information about the R-sig-DB mailing list