Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

find_each and find_in_batches assumes that primary key is a number

#5861

They do not work when primary key is a string.

::Translation::Key.find_each() {|r| }

ActiveRecord::StatementInvalid: PGError: ERROR:  operator does not exist: character varying >= integer
LINE 1: ...slation_keys"  WHERE     ("translation_keys"."id" >= 0) ORDE...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT     "translation_keys".* FROM       "translation_keys"  WHERE     ("translation_keys"."id" >= 0) ORDER BY  translation_keys.id ASC LIMIT 1000
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:202:in `rescue in log'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:194:in `log'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:496:in `execute'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:982:in `select_raw'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:975:in `select'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/query_cache.rb:56:in `select_all'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/base.rb:467:in `find_by_sql'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/relation.rb:64:in `to_a'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/relation/finder_methods.rb:143:in `all'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/relation/batches.rb:68:in `find_in_batches'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/relation/batches.rb:20:in `find_each'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/base.rb:440:in `find_each'
    from (irb):15
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in `start'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in `start'
    from /home/rupert/.rvm/gems/ruby-1.9.2-head/gems/railties-3.0.1/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'ruby-1.9.2-head >

temporary workaround:

start = Object.new
def start.to_i
  ""
end
::Translation::Key.find_each(:start => start) do |record|
This line:
start = options.delete(:start).to_i
from
ruby-1.9.2-head/gems/activerecord-3.0.1/lib/active_record/relation/batches.rb
defaults "start" variable to 0.

Reported by Robert Pankowecki · October 25th, 2010 @ 04:30 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Robert Pankowecki
    Robert Pankowecki
    • Tag changed from active record, find_each, find_in_batches, primary_key, string to active record, find_each, find_in_batches, primary_key, rails3, rails3.0.1, string

    October 25th, 2010 @ 04:32 PM

  2. Denis Odorcic
    Denis Odorcic

    From the comments:

    # It's not possible to set the order. That is automatically set to
    # ascending on the primary key ("id ASC") to make the batch ordering
    # work. This also mean that this method only works with integer-based
    # primary keys. You can't set the limit either, that's used to control
    # the the batch sizes.
    

    Guessing this'll be tagged as a wontfix

    October 27th, 2010 @ 01:54 AM

  3. Robert Pankowecki
    Robert Pankowecki

    Is there any particular reason why this should only work on integer ids ? I see no reason for such restriction.

    October 27th, 2010 @ 10:49 PM

  4. Kane
    Kane

    i agree with robert

    October 28th, 2010 @ 06:19 PM

  5. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 1st, 2010 @ 05:04 PM

  6. rails
    rails
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 26th, 2011 @ 12:00 AM

  7. rails
    rails
    • State changed from open to stale

    February 26th, 2011 @ 12:00 AM