-
Notifications
You must be signed in to change notification settings - Fork 82
Open
Description
It seems when passing in a Time object set to at_end_of_day as an arg, it somehow loses the precision and rolls in to the beginning of the next day.
Here's an example where I generate a date series. The first SQL has the time set manually, and when ran, it returns 1 result properly. The second SQL pulls the times from Crystal and passes it over as as args. Even though the Crystal times have the same values, running this SQL returns 2 results instead of 1.
class Date
DB.mapping({date: String})
end
working_sql = <<-SQL
SELECT
date::text
FROM GENERATE_SERIES(date('2022-05-01T00:00:00.000000000Z'), date('2022-05-01T23:59:59.999999999Z'), '1 DAY') AS date
SQL
borked_sql = <<-SQL
SELECT
date::text
FROM GENERATE_SERIES(date($1), date($2), '1 DAY') AS date
SQL
url = "postgres://postgres@localhost:5432"
DB.open(url) do |db|
single_result = db.query_all(working_sql, as: Date)
pp! single_result
day_start = Time.utc(2022, 5, 1).at_beginning_of_day
day_end = Time.utc(2022, 5, 1).at_end_of_day
double_results = db.query_all(borked_sql, args: [day_start, day_end], as: Date)
pp! double_results
endReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels