Skip to content
Prev 1065 / 1559 Next

Postgres to R date conversion and Writing NULL to postgres database using RpgSQL issue

On Thu, Apr 21, 2011 at 6:32 AM, subodh agrawal <subodh.iitr at gmail.com> wrote:
Thanks.  This reproduces the error.

library(RpgSQL)
DF <- data.frame(a = c(1, NA, 2), b = c(Sys.Date() + 1:2, NA), c =
c("a", NA, "b"))
con <- dbConnect(pgSQL(), user = "whatever", password = "whatever",
dbname = "whatever")
dbWriteTable(con, "DF", DF)
Continuing from above the following works in the development version
of RpgSQL (although the writeTable above is still a problem in the
development version). The NA fields are stored as NULLs and then
converted back to NAs.  (In the released version the code below only
works for character columns.)

DF2 <- DF[-2]
dbWriteTable(con, "DF2", DF2)
dbGetQuery(con, "select * from DF")

I can send you the development version if you need it now.