I've got a lot (+100,000) of records I'm trying to process through a query.
I was using something like:
BigRecordPull.where(name: ['x','y','z']).each { |record| do_some_action record }
Because this isn't good from a memory management perspective, I wanted to instead use find_each as outlined here so now the code looks like this:
BigRecordPull.where(name: ['x','y','z']).find_each { |record| do_some_action record }
The issue is when I go to fire the code I get the following error:
ActiveRecord::JDBCError: ERROR: operator does not exist: character varying >= integer Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
If I review the SQL query created in the logs I get back something like:
SELECT "big_record_pull".* FROM "big_record_pull" WHERE "big_record_pull"."name" IN ('x','y','z') AND ("big_record_pull"."name" >= 0)
ActiveRecord seems to add the part, 'AND ("big_record_pull"."name" >= 0)' and that seems to be what's causing the problem. Name in this example is a varchar. The extra wrinkle is I don't control the postgresql db my rails project plugs into so I can't just re-run a migration to try and fix this issue. I'm hoping there's some sort of work around.... I'd like to avoid running raw SQL.
Aucun commentaire:
Enregistrer un commentaire