开发者

Ruby on Rails timestamp is being converted into numeric by PostgreSQL on Heroku

开发者 https://www.devze.com 2023-04-09 19:12 出处:网络
I will start out by saying there is a question similar to mine: heroku Postgres error - operator does not exist timestamp without timezone = integer

I will start out by saying there is a question similar to mine:

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

but it did not solve my problem. What I am looking at is this error in the worker on 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

The problem is, somehow Ruby on Rails or PostgreSQL converted a timestamp into this weird decimal.

The query it is trying to do in Ruby on Rails looks something like this:

BuzzTopic.first( :conditions => [ "version = ?", Feature.current_version ] )

BuzzTopic has a named_scope called current that looks similar to this.

Feature.current_version is just a timestamp:

>> Feature.current_version
=> Mon, 26 Sep 2011 07:06:41 UTC +00:00

BuzzTopic.version is also just a timestamp.

Using that query in heroku run console works, however it does not work when the worker runs it. Here is a list of things I have tried so far:

I tried converting Feature.current_version into a format like "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

and tried different named_scopes for 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 ] } }

None of these worked, and I definitely tried some others that I forgot about. I am stuck and don't know what to do, so I came here. Can anyone help?


Actually, the problem was due to some code that I left unchanged when I was solving another problem. Instead of passing a timestamp and a decimal in a block, it only passed the decimal. Now that I fixed that, this problem is solved.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号