[R-sig-DB] RdbiPgSQL: Sub-second support for type conversion
Dirk Eddelbuettel
edd @end|ng |rom deb|@n@org
Mon Mar 5 20:33:09 CET 2007
Brian Ripley did a lot of really nice work a year ago to support milli- (and
even micro-) second resolutions in R's POSIXt types.
Trying to read such data back from Postgresql, I was getting
> Foo <- dbReadTable(db, someTable)
Warning messages:
1: Coercing PGSQL type 1114 to character in:
rpgsql.cast.values.default(data.col)
for columns of type timestamp (actually: 'timestamp without time zone').
As I use
options("digits.secs"=7)
a simple Sys.time() returns strings such
> Sys.time()
[1] "2007-03-05 13:28:39.260931 CST"
Now, I just had a really quick look at the RdbiPgSQL sources, and it turns
out that I can solve my problem with a simple one-liner similar to what is
already at the end of R/types.R:
## indented just for the mail
rpgsql.cast.values.1114 <- function(x) {
as.POSIXct(strptime(x, "%a %b %d %H:%M:%OS %Y"))
}
But i presume that the format string is locale-dependent. Is there a clever
way to code the format in a way that will work in other settings?
Dirk
--
Hell, there are no rules here - we're trying to accomplish something.
-- Thomas A. Edison
More information about the R-sig-DB
mailing list