Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MySQL 5.6 and later supports microsecond precision in datetime.
You might want to branch it to include this only for 5.6, but passing these values to < 5.6 doesn't cause issues either.
- Loading branch information
df5a38f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it does. Let's consider following usecase. you insert some records, which recieve a created at.
which will generate the query
So you would expect it to return the first 2 records but not the last one, because the it's created is exactly
2014-11-24 13:41:38.39479
but not less than it.However this is not what will happen on mysql below 5.6. Below 5.6 all the records will be stored without the microsecond timestamp. So the last record will be stored with
created_at: "2014-11-22 13:41:38"
.And for the comparison of dates mysql, will just do a lexical comparison. So
2014-11-22 13:41:38
is actually less than2014-11-24 13:41:38.394797
and the query will return the last record also.I.d.k why, but we experience this behavior on 5.6 either. The timestamps have been truncated on insert.
This implementation of microseconds also ignores the fact, that a a precision was set manually.
You can define the precision of timestamps for db queries by setting
Time::DATE_FORMATS[:db]
. If you then pass a datetime like object to an AR query it will automatically respect this setting.So
will result in
See issue #19223