Kad Kerforn
2006-Dec-19 05:19 UTC
find all where column value exist in an array (no loop?)
I would like to find all records from a table where a column value exist in an array.. like this @city_array = [''125'', ''459'', ''748'',..... ''9654'', ''12459''] # can be over 500 id''s @condition = [''WHERE city_id IN ?'', @city_array] @proposals = Proposals.find (:all, :condition => @condition) if this set of values is small , that''s fine, but when the array size is big, it can explode the string size limit of the where clause... or I can loop over the array ids, but so long.. performance... any suggestions ? thanks kad -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2006-Dec-19 16:39 UTC
Re: find all where column value exist in an array (no loop?)
On Dec 19, 2006, at 12:19 AM, Kad Kerforn wrote:> I would like to find all records from a table where a column value > exist > in an array.. > like this > > @city_array = [''125'', ''459'', ''748'',..... ''9654'', ''12459''] # can be > over > 500 id''s > @condition = [''WHERE city_id IN ?'', @city_array] > @proposals = Proposals.find (:all, :condition => @condition) > > if this set of values is small , that''s fine, but when the array > size is > big, it can explode the string size limit of the where clause... > > or I can loop over the array ids, but so long.. performance... > > any suggestions ? > > thanks > > kadDid the array (@city_array) values come from the database? If so, you can probably do better letting the database do the JOIN. Post a bit more code and you might get more help. (The relevant schema and models might help, too.) -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---