【发布时间】:2011-09-30 06:18:03
【问题描述】:
首先我会说有一个与我类似的问题:
heroku Postgres error - operator does not exist timestamp without timezone = integer
但这并没有解决我的问题。我正在查看的是 Heroku 上的工作人员中的此错误:
[Worker(host:026e9a98-87ae-4c0c-94c8-315843e68ac1 pid:1)] Buzz#digest! failed with ActiveRecord::StatementInvalid: PGError: ERROR: operator does not exist: timestamp without time zone = numeric
LINE 1: ...FROM "buzz_topics" WHERE ("buzz_topics"."version" = 0.069980...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
SELECT * FROM "buzz_topics" WHERE ("buzz_topics"."version" = 0.0699802335812795) AND ("buzz_topics".buzz_id = 696) LIMIT 1 - 0 failed attempts
问题是,Ruby on Rails 或 PostgreSQL 不知何故将时间戳转换成这个奇怪的小数。
它试图在 Ruby on Rails 中执行的查询看起来像这样:
BuzzTopic.first( :conditions => [ "version = ?", Feature.current_version ] )
BuzzTopic 有一个名为 current 的 named_scope,看起来与此类似。
Feature.current_version 只是一个时间戳:
>> Feature.current_version
=> Mon, 26 Sep 2011 07:06:41 UTC +00:00
BuzzTopic.version 也只是一个时间戳。
在heroku run console 中使用该查询有效,但是当工作人员运行它时它不起作用。以下是我迄今为止尝试过的事情的清单:
我尝试将Feature.current_version 转换为类似“2011-09-26 07:06:41”的格式:
def self.current_version # original
last_feature = enabled.last
last_feature.present? ? last_feature.version : nil
end
def self.current_version
last_feature = enabled.last
last_feature.present? ? last_feature.version.utc.to_formatted_s( :db ) : nil
end
并为BuzzTopic 尝试了不同的命名范围:
named_scope :current, lambda { { :conditions => { :version => Feature.current_version } } } # original
named_scope :current, lambda { { :conditions => [ "version = to_timestamp( ? )", Feature.current_version ] } }
named_scope :current, lambda { { :conditions => [ "version = timestamp ?", Feature.current_version ] } }
这些都不起作用,我肯定尝试了一些我忘记的其他方法。我被困住了,不知道该怎么办,所以我来到了这里。有人可以帮忙吗?
【问题讨论】:
标签: ruby-on-rails postgresql heroku timestamp