Hi, I''m having a problem with the automatic formatting of my mysql query. My code is this: Tablename.find(:all, :conditions => {:id => list}) Where list is a list of id''s (8,9,10) The problem is that the query is automatically formatted to this: SELECT * FROM Tablename WHERE (id in (''8,7,9'')) I need this query to run without the extra single quotes to work properly. ie: SELECT * FROM identifications WHERE (id in (8,7,9)) How do I go about this? Thanks, Jonathon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 6/26/07, Jonathon Paul Martin <jonathon.p.martin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''m having a problem with the automatic formatting of my mysql query. > > My code is this: > > Tablename.find(:all, :conditions => {:id => list}) > > Where list is a list of id''s (8,9,10) > > The problem is that the query is automatically formatted to this: > > SELECT * FROM Tablename WHERE (id in (''8,7,9'')) > > I need this query to run without the extra single quotes to work properly. > > ie: SELECT * FROM identifications WHERE (id in (8,7,9)) > > How do I go about this?list needs to be an Array, not a String: list = [8,7,9] # array of values It looks like you have list as a string "8,7,9", which is a single value. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jonathon Paul Martin
2007-Jun-26 19:12 UTC
Re: MySQL Where conditions automatic formatting
Thanks On 6/26/07, Bob Showalter <showaltb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 6/26/07, Jonathon Paul Martin <jonathon.p.martin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > > > I''m having a problem with the automatic formatting of my mysql query. > > > > My code is this: > > > > Tablename.find(:all, :conditions => {:id => list}) > > > > Where list is a list of id''s (8,9,10) > > > > The problem is that the query is automatically formatted to this: > > > > SELECT * FROM Tablename WHERE (id in (''8,7,9'')) > > > > I need this query to run without the extra single quotes to work > properly. > > > > ie: SELECT * FROM identifications WHERE (id in (8,7,9)) > > > > How do I go about this? > > list needs to be an Array, not a String: > > list = [8,7,9] # array of values > > It looks like you have list as a string "8,7,9", which is a single value. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---