Skip to content

Instantly share code, notes, and snippets.

@PetrKaleta
Last active August 29, 2015 14:03
Show Gist options
  • Save PetrKaleta/704639f9e9bf8798b815 to your computer and use it in GitHub Desktop.
Save PetrKaleta/704639f9e9bf8798b815 to your computer and use it in GitHub Desktop.
Strange microseconds issue when querying by time
# Please have a look, how updated_at timestamp is represented in generated SQL
# In this example everything is OK
Event.where(Sequel.expr(:updated_at) > Time.at(1405338941.821000)).sql
# => "SELECT * FROM \"events\" WHERE (\"updated_at\" > '2014-07-14 13:55:41.821000+0200')"
# In this example, there's a precision issue (see microseconds), why?
Event.where(Sequel.expr(:updated_at) > Time.at(1405341161.918000)).sql
# => "SELECT * FROM \"events\" WHERE (\"updated_at\" > '2014-07-14 14:32:41.917999+0200')"
# So lets try pure parsing, but everything seems to be ok.
# Am I doing something wrong?
"%10.6f" % Time.at(1405341161.918000).to_f
# => "1405341161.918000"
"%10.6f" % Time.at(1405338941.821000).to_f
# => "1405338941.821000"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment