postgresql heroku Postgres 错误 - 没有时区 = 整数的运算符不存在时间戳

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3121698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 22:36:01  来源:igfitidea点击:

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

postgresqloperatorsheroku

提问by Timothy T.

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.

虽然它在我的本地 sqlite 上运行良好,但我有一个“没有时区 = 整数的运算符不存在时间戳”错误。

I'm not exactly clear what to change.

我不太清楚要改变什么。

Ideas?

想法?

Thanks.

谢谢。

回答by Frank Heikens

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.

您的参数 @monday 和 @friday 是错误的,它们的类型必须是“没有时区的时间戳”,但被创建为整数,请参阅错误消息。SQLite 没有任何日期时间数据类型,因此日期存储为文本或整数(unix 时间戳)。这就是您在 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:

确保你创建了像“2004-10-19 10:23:54”这样的时间戳,你会没事的。另一种选择可能是 PostgreSQL 函数to_timestamp()将您的 unix-timestamp 转换为时间戳:

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