Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using the following code in my 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 an "operator does not exist timestamp without timezone = integer" error.

I'm not exactly clear what to change.

Ideas?

Thanks.

like image 295
Satchel Avatar asked Jun 25 '10 21:06

Satchel


1 Answers

Your parameters @monday and @friday are wrong, these have to be of type "timestamp without time zone" but are created as integers, see the errormessage. SQLite doesn't have any datetime-datatypes, so dates are stored as text or integers (unix-timestamps). This is why you don't get an errormessage in SQLite.

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

@sent_emails = ContactEmail.all(:conditions => ['date_sent >= to_timestamp(?) and date_sent <= to_timestamp(?)', @monday, @friday])
like image 111
Frank Heikens Avatar answered Sep 21 '22 19:09

Frank Heikens