postgresql - Translate postgres VARCHAR query into ruby activerecord -
i need translate following postgresql query activerecord ruby query.
select * my_table (my_time between '2010-12-27 00:00:00' , '2011-01-28 00:00:00') , (my_time::time)::varchar '12:00:00.%';
this pulls out 12:00:00.% piece of data each day. can time range part, don't know how translate second half of query.
thanks
you use to_char
convert timestamp appropriate string form , strip off fractional seconds @ same time:
where to_char(my_time, 'hh24:mm:ss') = '12:00:00' ...
the activerecord version of pretty simple:
mytable.where("to_char(my_time, 'hh24:mm:ss') = '12:00:00'")
then chain in existing between check.
you use extract
check each time component separately:
where extract(hour my_time) = 12 , extract(minute my_time) = 0 , extract(second my_time) = 0 ...
the activerecord version of be:
mytable.where('extract(hour my_time) = ?', 12) .where('extract(minute my_time) = ?', 0) .where('extract(second my_time) = ?', 0)
you'd have ask explain see version works best.
Comments
Post a Comment