[R-sig-DB] Data type error with RpgSQL on Windows XP SP3 32bit

Tomoaki NISHIYAMA tomo@k|n @end|ng |rom kenroku@k@n@z@w@-u@@c@jp
Mon Nov 1 06:42:56 CET 2010


Hi,

While the code presented by Gabor Grothendieck works fine.

 > options(RpgSQL.password = "", RpgSQL.dbname = "testdb",  
RpgSLQ.user="testuser")
 > con <- dbConnect(pgSQL())
 > ct <- 'CREATE TABLE DF ("a" INTEGER, "b" VARCHAR(255), "c"  
DATE,"d" DOUBLE PRECISION)'
 > dbSendUpdate(con, ct)
 > DF <- data.frame(a = 1L, b = "Hello", c = Sys.Date(), d = 32)
 > dbSendUpdate(con, "insert into DF values(1, 'Hello', to_date 
('2000-01-01', 'YYYY-MM-DD'), 32)")
 > res <- dbGetQuery(con, "select * from DF")
 > res
   a     b          c  d
1 1 Hello 2000-01-01 32


I found that when the database contain NULL value for the date field:
(This is prepared with psql)

testdb=# insert into df values ('2', 'bye', NULL,'48');
INSERT 0 1
testdb=# select * from df;
  a |   b   |     c      | d
---+-------+------------+----
  1 | Hello | 2000-01-01 | 32
  2 | bye   |            | 48
(2 rows)

Then, the original error (by Xiaobo Gu) could be reproduced.

 > res <- dbGetQuery(con, "select * from DF")
Error in as.Date.default(.jcall(res using jr, "S", "getString", i)) :
   do not know how to convert '.jcall(res using jr, "S", "getString", i)'  
to class "Date"

So, I guess there is some record with the c field having NULL value.
-- 
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