0

我在将数据从 edb postgres 导入 R(使用 RPostgres)时遇到问题。我使用这段代码:

library(RPostgres)
conn <- dbConnect(Postgres(), dbname = 'xx', host = 'xx', port = 'xx', 
                  user = 'xx', password = 'xx',
                  options="-c search_path=xx")

a=dbGetQuery(conn, "SELECT * FROM xx")

将数据导入 R 后一切正常,所有带有日期的列都损坏了。几个例子:

postgres value: 2009-11-02  after importing in R: 0231-08-11
postgres value: 2009-08-12  after importing in R: 1206-01-15

该列在 postgres 中的数据类型是日期。如果我通过查询从 postgres 列(日期)中读取:

".. to_char(column_with_date, 'DD-MM-YYYY') as column_with_date .." 

然后我在 R 中得到好的数据,但 R 中的数据类型不是日期而是字符。

我尝试将相同的数据从 mysql 库导入 R(使用 RMySQL),在这种情况下数据是未损坏的。使用的代码:

library(RMySQL)
conn <-  dbConnect(MySQL(), user = "xx", password = "xx", dbname = "xx", host = "xx" )
a=dbGetQuery(conn,"select* from xx ")

谢谢

4

0 回答 0