Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date columns #17

Closed
ggrothendieck opened this issue Oct 27, 2014 · 8 comments
Closed

Date columns #17

ggrothendieck opened this issue Oct 27, 2014 · 8 comments

Comments

@ggrothendieck
Copy link
Contributor

RMySQL seems to use text for Date (and POSIXct) columns. It should use MySQL date type and datetime or timestamp type and convert correctly in both directions.

library(RMySQL)

t1 <- data.frame(d = as.Date("2001-01-30"))
con <- dbConnect("MySQL", "test")
dbWriteTable(con, "t1", t1, row.names = FALSE)
dbGetQuery(con, "describe t1")

which produces:

  Field Type Null Key Default Extra
1     d text  YES        <NA>

but d should be of MySQL date type, not text.

packageVersion("RMySQL")
[1] ‘0.9.3’
packageVersion("DBI")
[1] ‘0.3.1’
R.version.string
[1] "R version 3.1.1 Patched (2014-08-21 r66456)"

@hadley
Copy link
Member

hadley commented Dec 29, 2014

This should be a straightforward fix to dbDataType(), although making sure the dates are correctly loaded back into R might be harder.

@elbamos
Copy link

elbamos commented Jan 10, 2015

Came to raise the same issue, but its already here, so I guess this is a +1.

@hadley
Copy link
Member

hadley commented Feb 17, 2015

In the dev version, DATETIMEs and TIMESTAMPs are retrieved as POSIXct, and DATEs are retrieved as Dates. Will have similar code for sending shortly

@elbamos
Copy link

elbamos commented Feb 17, 2015

Thanks Hadley - please let me know how I can help.

On Feb 17, 2015, at 10:44 AM, Hadley Wickham notifications@github.com wrote:

In the dev version, DATETIMEs and TIMESTAMPs are retrieved as POSIXct, and DATEs are retrieved as Dates. Will have similar code for sending shortly


Reply to this email directly or view it on GitHub.

@hadley hadley closed this as completed in e9ced2d Feb 17, 2015
@hadley
Copy link
Member

hadley commented Feb 17, 2015

Dealing with timezones was tricky, but I'm pretty sure it's correct now.

@ywhcuhk
Copy link

ywhcuhk commented May 18, 2015

run into the same problem. Date column from R data frame is still loaded as text if I send the dataframe to Mysql. My RMySQL version is 0.10.3

@ChristopherCosler
Copy link

Experiencing the same problem as ywhuofu. Has it not been fixed or are we using it wrong?

@martinschmelzer
Copy link

Might be experiencing the same (or at least closely related) issue. I write POSIXct objects into a DATETIME column. In phpMyAdmin everything looks fine. When I retrieve the data with

q <- dbSendQuery(con, "SELECT * FROM table LIMIT 10")
test <- dbFetch(q)

The DATETIME column only contains the value 1970-01-01 00:59:59 all over the table. Same applies to a column of type TIMESTAMP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants