【发布时间】:2014-09-02 04:33:02
【问题描述】:
有一个带有表 Content::Translation 的旧数据库,其中包含 text、resource_id 和 ayah_key 列
resource_id = 整数,
ayah_key = 字符串
我的模特:
class Content::Translation < ActiveRecord::Base
extend Content
self.table_name = 'translation'
self.primary_keys = :ayah_key, :resource_id
end
当使用 Elasticsearch 建立索引时,它会创建一个 1000 的批处理查询,这会产生 PSQL 错误:
SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "content"."translation" WHERE ("content"."translation"."ayah_key" >= 0) AND ("content"."translation"."resource_id" >= 0) LIMIT 1000) subquery_for_count
PG::UndefinedFunction: ERROR: operator does not exist: text >= integer
LINE 1: ...ation" WHERE ("content"."translation"."ayah_key" >= 0) AND ...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "content"."translation" WHERE ("content"."translation"."ayah_key" >= 0) AND ("content"."translation"."resource_id" >= 0) LIMIT 1000) subquery_for_count
ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: operator does not exist: text >= integer
LINE 1: ...ation" WHERE ("content"."translation"."ayah_key" >= 0) AND ...
这是因为我的 ayah_key 列是一个字符串,我确实需要该列是一个字符串。有没有一种方法可以让我编写一个范围或做一些事情,以便与>= '0' 进行比较?
【问题讨论】:
标签: ruby-on-rails postgresql activerecord