我首先会说有一个类似于我的问题:
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:
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 ] } }
这些都没有奏效,我确实尝试过其他一些我忘了的东西。我被困住了,不知道该怎么办,所以我来到这里。有人可以帮忙吗?
答案 0 :(得分:0)
实际上,问题是由于某些代码在我解决另一个问题时保持不变。它不是在块中传递时间戳和小数,而是只传递小数。现在我解决了这个问题,这个问题就解决了。