heroku Postgres错误 - 运算符不存在timezone = integer的时间戳 [英] heroku Postgres error - operator does not exist timestamp without timezone = integer

查看:907
本文介绍了heroku Postgres错误 - 运算符不存在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没有任何日期时间数据类型,所以日期以文本或整数存储(unix-timestamps)。这就是为什么你不会在SQLite中得到错误消息。



确保你创建'2004-10-19 10:23:54'等时间戳,你将会精细。另一个选项可以是PostgreSQL函数 to_timestamp()来转换您的unix-timestamp添加到时间戳:

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


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.

解决方案

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

这篇关于heroku Postgres错误 - 运算符不存在timezone = integer的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆