【发布时间】:2012-05-31 13:15:34
【问题描述】:
我收到以下错误:
PGError: ERROR: operator does not exist: character varying >= integer
LINE 1: ...CT "games".* FROM "games" WHERE ("games"."uuid" >= 0) ORDE...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT "games".* FROM "games" WHERE ("games"."uuid" >= 0) ORDER BY "games"."uuid" ASC LIMIT 1000
当我尝试这样做时:
Game.find_each do |game|
# ...
end
我的模型有一个字符串 (UUID) 主键:
class Game < ActiveRecord::Base
self.primary_key = 'uuid'
before_create do |game|
game.uuid = UUIDTools::UUID.timestamp_create().to_s if game.uuid.blank?
end
end
我不知道 ActiveRecord 为什么要放入 WHERE 子句,但这是完全没有必要的,也是类型错误的原因(因为它是字符串列,而不是整数列)。
那么,我该如何避免这种情况呢?我应该在我的模型定义中添加一些东西吗?或者我应该避免find_each 并使用不同的方法?这是一个 rake 任务,它只是遍历所有条目并查找一些附加信息......
【问题讨论】:
标签: ruby-on-rails ruby postgresql activerecord