Rails 3 - .each works, .find_each fails -> ActiveRecord::JDBCError: ERROR: operator does not exist: character varying >= integer -


i've got lot (+100,000) of records i'm trying process through query.

i using like:

bigrecordpull.where(name: ['x','y','z']).each { |record| do_some_action record } 

because isn't memory management perspective, wanted instead use find_each outlined here code looks this:

bigrecordpull.where(name: ['x','y','z']).find_each { |record| do_some_action record } 

the issue when go fire code following error:

activerecord::jdbcerror: error: operator not exist: character varying >= integer hint: no operator matches given name , argument type(s). might need add explicit type casts.

if review sql query created in logs like:

select  "big_record_pull".* "big_record_pull" "big_record_pull"."name" in ('x','y','z') , ("big_record_pull"."name" >= 0)  

activerecord seems add part, 'and ("big_record_pull"."name" >= 0)' , seems what's causing problem. name in example varchar. wrinkle don't control postgresql db rails project plugs can't re-run migration try , fix issue. i'm hoping there's sort of work around.... i'd avoid running raw sql.

extra info in example above, big_record_pull.name foreign_key

ok, problem related gem: composite_primary_keys-5.0.14.gem.

solution found, here

see lib/composite_primary_keys/relation/batches.rb:28:in `find_in_batches' change block to:

  self.primary_key.each |key|       condition = case relation.columns_hash[key.to_s].type         when :string           table[key].not_eq ''         when :integer           table[key].gteq start       end       relation = relation.where(condition)     end 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -