2011-09-30 28 views
0

我會說有類似地雷問題開始了。我所看到的是在Heroku上出現此錯誤工人:Ruby on Rails的時間戳被轉換成數字PostgreSQL可以在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有一個稱爲當前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 7時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 

,並嘗試不同的named_scopes爲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 ] } } 

這些都沒有工作,我絕對嘗試了一些我忘記了。我被卡住了,不知道該怎麼做,所以我來到了這裏。誰能幫忙?

回答

0

實際上,這個問題是由於一些代碼在我解決另一個問題時保持不變。它不是在塊中傳遞時間戳和小數,而只是傳遞小數。現在我解決了這個問題,這個問題就解決了。