This project is archived and is in readonly mode.

#5861 ✓stale
Robert Pankowecki

find_each and find_in_batches assumes that primary key is a number

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

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.

Comments and changes to this ticket

  • Robert Pankowecki

    Robert Pankowecki October 25th, 2010 @ 04:32 PM

    • 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
  • Denis Odorcic

    Denis Odorcic October 27th, 2010 @ 01:54 AM

    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

  • Robert Pankowecki

    Robert Pankowecki October 27th, 2010 @ 10:49 PM

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

  • Kane

    Kane October 28th, 2010 @ 06:19 PM

    i agree with robert

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer November 1st, 2010 @ 05:04 PM

    • Tag cleared.
    • Importance changed from “” to “Low”

    Automatic cleanup of spam.

  • rails

    rails February 26th, 2011 @ 12:00 AM

    • 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.

  • rails

    rails February 26th, 2011 @ 12:00 AM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages