Heroku Postgres error - operator does not exist timestamp without timezone = integer

I use the following code in the controller:

@monday = (Time.now).at_beginning_of_week @friday = 5.days.since(@monday)-1.second @sent_emails = ContactEmail.all(:conditions => ['date_sent >= ? and date_sent <= ?', @monday, @friday]) 

Although it works fine on my local sqlite, I have the error "operator not exist timestamp without timezone = integer".

I do not quite understand what to change.

Ideas?

Thanks.

+6
operators postgresql heroku
source share
1 answer

Your @monday and @friday parameters are wrong, they must be of type "timestamp without time zone", but they are created as integers, see errormessage. SQLite does not have datetime-datatypes types, so dates are stored as text or integers (unix-timestamps). This is why you are not getting errormessage in SQLite.

Make sure you create timestamps such as '2004-10-19 10:23:54' and everything will be fine. Another option might be the PostgreSQL to_timestamp () function to convert your unix timestamp to a timestamp:

 @sent_emails = ContactEmail.all(:conditions => ['date_sent >= to_timestamp(?) and date_sent <= to_timestamp(?)', @monday, @friday]) 
+7
source share

All Articles