繁体   English   中英

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

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

我在我的控制器中使用以下代码:

  @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])

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

我不清楚要改变什么。

想法?

谢谢。

您的参数@monday和@friday是错误的,这些参数必须是“没有时区的时间戳”类型,但是创建为整数,请参阅errormessage。 SQLite没有任何datetime-datatypes,因此日期存储为文本或整数(unix-timestamps)。 这就是您在SQLite中没有得到错误消息的原因。

确保你创建像'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])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM