# Possible Active Record bug using :select in find method

**URL:** <https://www.ruby-forum.com/t/possible-active-record-bug-using-select-in-find-method/92034>\
**Category:** Rails\
**Created:** [April 15, 2007, 12:11am UTC](https://www.ruby-forum.com/t/possible-active-record-bug-using-select-in-find-method/92034 "2007-04-15T00:11:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wolleybook](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7feea3/32.png) [@wolleybook](https://www.ruby-forum.com/u/wolleybook)\
**Post date:** [April 15, 2007, 12:11am UTC](https://www.ruby-forum.com/t/possible-active-record-bug-using-select-in-find-method/92034/1 "2007-04-15T00:11:01Z")

</div>

Hi,

I am writing a small rails application that uses Ruby(1.8.5) with  
ActiveRecord (1.15.3) .

I realized that if i use the find method with the optional  
parameter :select with only the required columns to look for records  
in a table with 50,000 records as opposed to a find method without  
the :select option, the query is a lot faster. It took me 31 secs in  
the former case as opposed to 12 in the latter. I am using MySQL and  
my application is running on windows. (And yes, the table that I am  
querying is indexed).

Now my problem is that if i use :select the way it is mentioned in the  
rails documentation

Item.find( :all, :select =\> [:column1, :column2, :column3] ) or  
Item.find( :all, :select =\> [‘column1’, ‘column2’, ‘:column3’] )

It throws an error because it executes a query like:

select column1column2 column3 from items;

when there is no column like column1column2column3 in the table items.

However, If i modify my request and put a comma after each column  
name except on the last one

Item.find( :all, :select =\> [‘column1,’ , ‘column2,’ ,  
‘column3’] )

it works because this time it executes the query as noted below:

select column1,column2,column3 from items;

So I guess unless I am using some incompatible version, there could be  
a bug in ActiveRecord.  
Or am I missing something?

Thanks

---

<div class="post-metadata">

**Author:** ![wolleybook](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7feea3/32.png) [@wolleybook](https://www.ruby-forum.com/u/wolleybook)\
**Post date:** [April 15, 2007, 1:03am UTC](https://www.ruby-forum.com/t/possible-active-record-bug-using-select-in-find-method/92034/2 "2007-04-15T01:03:06Z")

</div>

> Now my problem is that if i use :select the way it is mentioned in the  
> rails documentation
> 
> Item.find( :all, :select =\> [:column1, :column2, :column3] ) or  
> Item.find( :all, :select =\> [‘column1’, ‘column2’, ‘:column3’] )

Where is that in the docs? :select should be a string. :select =\>  
“col1, col2, tbl2.\*”

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![wolleybook](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7feea3/32.png) [@wolleybook](https://www.ruby-forum.com/u/wolleybook)\
**Post date:** [April 15, 2007, 3:29am UTC](https://www.ruby-forum.com/t/possible-active-record-bug-using-select-in-find-method/92034/3 "2007-04-15T03:29:12Z")

</div>

My apologies. I should have checked in the official rails docs.  
I was referring to  
[Ruby on Rails Cheat Sheet Collectors Edition | Ruby on Rails Blog](http://www.rubyonrailsblog.com/articles/2006/10/04/ruby-on-rails-cheat-sheet-collectors-edition).

Thanks for clearing this up.
