On Friday, November 15, 2013 12:50:51 PM UTC-8, Rob Sullivan wrote:
>
> I have a table with a tsrange field and I use the follow query to figure 
> out if something falls on today:
>
> select * from burritotrucks where onsite @> '2013-11-15'::timestamp
>
> When I run a basic fetch command it works great:
> @eating = DB.fetch("select * from burritotrucks where onsite @> 
> '2013-11-15'::timestamp").all
>
> when I run it with the pg_range operators:
> @eating = DB[:burritotrucks].where(:onsite.pg_range.contains('2013-11-15'))
> or
> @eating = DB[:burritotrucks].where(:onsite.pg_range.contains(Date.today))
>
> it doesn't understand that the passed in value is supposed to be a 
> timestamp and not a date - thus throwing errors on the min/max boundaries.
>
> Any thoughts on how get it to understand that it's a timestamp?
>

The easiest way to get this to work is to cast manually, just as you do in 
the SQL:

  @eating = 
DB[:burritotrucks].where(:onsite.pg_range.contains(Sequel.cast(Date.today, 
Time)))

This could theoretically be handled automatically, if the date/timestamp 
literalization on PostgreSQL added such casts automatically.  But the issue 
at least for timestamps is which cast to use, timestamp or timestamptz.  I 
think it's possible that adding the casts automatically could break 
existing code, so I'm reluctant to do so by default.  However, I'd consider 
an extension that does so.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to