MySQL error comparing dates
I'm trying to query my database and return with entries that are within a certain date range. As a possible simple example consider the following:
@foos = FooTracking.where('when > ?', DateTime.new(2008, 12, 22, 14, 30))
Which causes an error and dumps:
ActiveRecord::StatementInvalid: Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'when >= '2008-12-22 14:30:00')' at line 1: SELECT `foo_tracking`.* FROM `foo_tracking` WHERE (when >= '2008-12-22 14:30:00')
开发者_运维问答The where call works on other columns of my table (none that have anything to do with dates), what am I missing here?
WHEN
is a SQL reserved word. You can still use it as a column name if you always mention it in backticks like this: `when`
.
精彩评论