Type casting options for Arel / ActiveRecord

In Postgres, these two queries are different:

-- Casts right hand string values to date since that's what we're comparing.
-- true
SELECT '2011-11-11'::date BETWEEN '2011-11-11 11:22:33' AND '2011-11-11 22:33:44'
-- Respects right hand types and compares timestamps to date at midnight
-- false
SELECT '2011-11-11'::date BETWEEN '2011-11-11 11:22:33'::timestamp AND '2011-11-11 22:33:44'::timestamp

When using Arel via ActiveRecord to compare columns against native Ruby values, Time objects just get quoted to database strings. e.g.

Model.where(check_in_date: time1..time2)
# or

I’m thinking of how this could be handled better for different types.

Could we consider adding type casting functions to Arel?

Should native Ruby types be cast to native database types by default?

Andrew Vit